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 *,
954 unsigned long & x, unsigned long & y) const
956 x = cursor.x() - top_x;
961 void InsetTabular::ToggleInsetCursor(BufferView * bv)
963 if (the_locking_inset) {
964 the_locking_inset->ToggleInsetCursor(bv);
968 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
970 int const asc = lyxfont::maxAscent(font);
971 int const desc = lyxfont::maxDescent(font);
974 bv->hideLockedInsetCursor();
976 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
977 cursor_visible = !cursor_visible;
981 void InsetTabular::ShowInsetCursor(BufferView * bv)
983 if (!cursor_visible) {
984 LyXFont font; // = GetFont(par, cursor.pos);
986 int const asc = lyxfont::maxAscent(font);
987 int const desc = lyxfont::maxDescent(font);
988 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
989 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
990 cursor_visible = true;
995 void InsetTabular::HideInsetCursor(BufferView * bv)
997 if (cursor_visible) {
998 bv->hideLockedInsetCursor();
999 cursor_visible = false;
1001 // if (cursor_visible)
1002 // ToggleInsetCursor(bv);
1006 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1011 actcell = actrow = actcol = 0;
1012 int ly = tabular->GetDescentOfRow(actrow);
1014 // first search the right row
1015 while((ly < y) && (actrow < tabular->rows())) {
1016 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1017 tabular->GetAscentOfRow(actrow+1) +
1018 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1021 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1023 actcell = tabular->GetCellNumber(actrow, actcol);
1025 // now search the right column
1026 int lx = tabular->GetWidthOfColumn(actcell) -
1027 tabular->GetAdditionalWidth(actcell);
1028 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
1029 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1030 tabular->GetAdditionalWidth(actcell - 1));
1033 if ((lx - (tabular->GetWidthOfColumn(actcell) / 2)) < x) {
1034 cursor.x(lx + top_x - 2);
1037 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1043 int InsetTabular::getCellXPos(int cell) const
1047 for(; !tabular->IsFirstCellInRow(c); --c)
1049 int lx = tabular->GetWidthOfColumn(cell);
1050 for(; (c < cell); ++c) {
1051 lx += tabular->GetWidthOfColumn(c);
1053 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1057 void InsetTabular::resetPos(BufferView * bv) const
1061 actcol = tabular->column_of_cell(actcell);
1066 for(; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1067 if (tabular->IsLastCellInRow(cell)) {
1068 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1069 tabular->GetAscentOfRow(actrow + 1) +
1070 tabular->GetAdditionalHeight(cell + 1));
1074 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1075 cursor.x(getCellXPos(actcell) + offset);
1076 if (((cursor.x() - offset) > 20) &&
1077 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1078 (bv->workWidth()-20)))
1080 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1081 UpdateLocal(bv, FULL, false);
1082 } else if ((cursor.x() - offset) < 20) {
1083 scroll(bv, 20 - cursor.x() + offset);
1084 UpdateLocal(bv, FULL, false);
1085 } else if (!cellstart(cursor.pos())) {
1086 LyXFont font(LyXFont::ALL_SANE);
1087 cursor.x(cursor.x() + tabular->GetCellInset(actcell)->width(bv,font) +
1088 tabular->GetBeginningOfTextInCell(actcell));
1090 if ((!the_locking_inset ||
1091 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1092 (actcell != oldcell)) {
1093 dialogs_ = bv->owner()->getDialogs();
1094 dialogs_->updateTabular(const_cast<InsetTabular *>(this));
1100 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1102 if (!cellstart(cursor.pos())) {
1103 if (tabular->IsLastCell(actcell))
1106 cursor.pos((cursor.pos() + 1) % 2);
1108 if (ActivateCellInset(bv))
1110 } else { // before the inset
1111 cursor.pos((cursor.pos() + 1) % 2);
1114 return DISPATCHED_NOUPDATE;
1118 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1120 if (!cursor.pos()) {
1125 cursor.pos((cursor.pos() - 1) % 2);
1126 if (!cellstart(cursor.pos())) {
1128 } else if (lock) { // behind the inset
1129 if (ActivateCellInset(bv, 0, 0, 0, true))
1133 return DISPATCHED_NOUPDATE;
1137 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv)
1139 int const ocell = actcell;
1140 actcell = tabular->GetCellAbove(actcell);
1141 if (actcell == ocell) // we moved out of the inset
1144 return DISPATCHED_NOUPDATE;
1148 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv)
1150 int const ocell = actcell;
1151 actcell = tabular->GetCellBelow(actcell);
1152 if (actcell == ocell) // we moved out of the inset
1155 return DISPATCHED_NOUPDATE;
1159 bool InsetTabular::moveNextCell(BufferView * bv)
1161 if (tabular->IsLastCell(actcell))
1164 cursor.pos((cursor.pos() + 1) % 2);
1165 if (!cellstart(cursor.pos()))
1166 cursor.pos((cursor.pos() + 1) % 2);
1172 bool InsetTabular::movePrevCell(BufferView * bv)
1174 if (!actcell) // first cell
1177 cursor.pos((cursor.pos() - 1) % 2);
1178 if (cellstart(cursor.pos()))
1179 cursor.pos((cursor.pos() - 1) % 2);
1185 bool InsetTabular::Delete()
1191 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1193 if (the_locking_inset)
1194 the_locking_inset->SetFont(bv, font, tall);
1198 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1200 int action = LyXTabular::LAST_ACTION;
1203 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1204 string const tmp = tabularFeatures[i].feature;
1206 if (tmp == what.substr(0, tmp.length())) {
1207 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1208 //tabularFeatures[i].feature.length())) {
1209 action = tabularFeatures[i].action;
1213 if (action == LyXTabular::LAST_ACTION)
1217 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1218 TabularFeatures(bv, action, val);
1223 void InsetTabular::TabularFeatures(BufferView * bv, int feature,
1224 string const & value)
1233 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1238 case LyXTabular::M_ALIGN_LEFT:
1239 case LyXTabular::ALIGN_LEFT:
1240 setAlign=LYX_ALIGN_LEFT;
1242 case LyXTabular::M_ALIGN_RIGHT:
1243 case LyXTabular::ALIGN_RIGHT:
1244 setAlign=LYX_ALIGN_RIGHT;
1246 case LyXTabular::M_ALIGN_CENTER:
1247 case LyXTabular::ALIGN_CENTER:
1248 setAlign=LYX_ALIGN_CENTER;
1250 case LyXTabular::M_VALIGN_TOP:
1251 case LyXTabular::VALIGN_TOP:
1252 setAlign=LyXTabular::LYX_VALIGN_TOP;
1254 case LyXTabular::M_VALIGN_BOTTOM:
1255 case LyXTabular::VALIGN_BOTTOM:
1256 setAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1258 case LyXTabular::M_VALIGN_CENTER:
1259 case LyXTabular::VALIGN_CENTER:
1260 setAlign=LyXTabular::LYX_VALIGN_CENTER;
1265 if (hasSelection()) {
1266 sel_col_start = tabular->column_of_cell(sel_cell_start);
1267 sel_col_end = tabular->column_of_cell(sel_cell_end);
1268 if (sel_col_start > sel_col_end) {
1269 sel_col_end = sel_col_start;
1270 sel_col_start = tabular->column_of_cell(sel_cell_end);
1272 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1275 sel_row_start = tabular->row_of_cell(sel_cell_start);
1276 sel_row_end = tabular->row_of_cell(sel_cell_end);
1277 if (sel_row_start > sel_row_end) {
1278 //int tmp = sel_row_start;
1279 //sel_row_start = sel_row_end;
1280 //sel_row_end = tmp;
1281 swap(sel_row_start, sel_row_end);
1284 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1285 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1287 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1289 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1290 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1292 bv->text->cursor.par()->previous,
1293 bv->text->cursor.par()->next
1297 int row = tabular->row_of_cell(actcell);
1298 int column = tabular->column_of_cell(actcell);
1302 case LyXTabular::SET_PWIDTH:
1304 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1305 tabular->SetColumnPWidth(actcell,value);
1307 for (int i=0; i < tabular->rows(); ++i) {
1308 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1311 UpdateLocal(bv, INIT, true);
1315 case LyXTabular::SET_MPWIDTH:
1317 bool const update = (tabular->GetPWidth(actcell) != value);
1318 tabular->SetMColumnPWidth(actcell,value);
1320 for (int i=0; i < tabular->rows(); ++i) {
1321 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1324 UpdateLocal(bv, INIT, true);
1328 case LyXTabular::SET_SPECIAL_COLUMN:
1329 case LyXTabular::SET_SPECIAL_MULTI:
1330 tabular->SetAlignSpecial(actcell,value,feature);
1332 case LyXTabular::APPEND_ROW:
1333 // append the row into the tabular
1334 UnlockInsetInInset(bv, the_locking_inset);
1335 tabular->AppendRow(actcell);
1336 UpdateLocal(bv, INIT, true);
1338 case LyXTabular::APPEND_COLUMN:
1339 // append the column into the tabular
1340 tabular->AppendColumn(actcell);
1341 actcell = tabular->GetCellNumber(row, column);
1342 UpdateLocal(bv, INIT, true);
1344 case LyXTabular::DELETE_ROW:
1345 tabular->DeleteRow(tabular->row_of_cell(actcell));
1346 if ((row+1) > tabular->rows())
1348 actcell = tabular->GetCellNumber(row, column);
1349 UpdateLocal(bv, INIT, true);
1351 case LyXTabular::DELETE_COLUMN:
1352 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1353 if ((column+1) > tabular->columns())
1355 actcell = tabular->GetCellNumber(row, column);
1356 UpdateLocal(bv, INIT, true);
1358 case LyXTabular::M_TOGGLE_LINE_TOP:
1360 case LyXTabular::TOGGLE_LINE_TOP:
1361 lineSet = !tabular->TopLine(actcell, flag);
1362 for(i=sel_row_start; i<=sel_row_end; ++i)
1363 for(j=sel_col_start; j<=sel_col_end; ++j)
1364 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1365 UpdateLocal(bv, INIT, true);
1368 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1370 case LyXTabular::TOGGLE_LINE_BOTTOM:
1371 lineSet = !tabular->BottomLine(actcell, flag);
1372 for(i=sel_row_start; i<=sel_row_end; ++i)
1373 for(j=sel_col_start; j<=sel_col_end; ++j)
1374 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1376 UpdateLocal(bv, INIT, true);
1379 case LyXTabular::M_TOGGLE_LINE_LEFT:
1381 case LyXTabular::TOGGLE_LINE_LEFT:
1382 lineSet = !tabular->LeftLine(actcell, flag);
1383 for(i=sel_row_start; i<=sel_row_end; ++i)
1384 for(j=sel_col_start; j<=sel_col_end; ++j)
1385 tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1387 UpdateLocal(bv, INIT, true);
1390 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1392 case LyXTabular::TOGGLE_LINE_RIGHT:
1393 lineSet = !tabular->RightLine(actcell, flag);
1394 for(i=sel_row_start; i<=sel_row_end; ++i)
1395 for(j=sel_col_start; j<=sel_col_end; ++j)
1396 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1398 UpdateLocal(bv, INIT, true);
1400 case LyXTabular::M_ALIGN_LEFT:
1401 case LyXTabular::M_ALIGN_RIGHT:
1402 case LyXTabular::M_ALIGN_CENTER:
1404 case LyXTabular::ALIGN_LEFT:
1405 case LyXTabular::ALIGN_RIGHT:
1406 case LyXTabular::ALIGN_CENTER:
1407 for(i = sel_row_start; i <= sel_row_end; ++i)
1408 for(j = sel_col_start; j <= sel_col_end; ++j)
1409 tabular->SetAlignment(tabular->GetCellNumber(i, j), setAlign,
1412 UpdateLocal(bv, INIT, true);
1414 UpdateLocal(bv, CELL, true);
1416 case LyXTabular::M_VALIGN_TOP:
1417 case LyXTabular::M_VALIGN_BOTTOM:
1418 case LyXTabular::M_VALIGN_CENTER:
1420 case LyXTabular::VALIGN_TOP:
1421 case LyXTabular::VALIGN_BOTTOM:
1422 case LyXTabular::VALIGN_CENTER:
1423 for(i = sel_row_start; i <= sel_row_end; ++i)
1424 for(j = sel_col_start; j <= sel_col_end; ++j)
1425 tabular->SetVAlignment(tabular->GetCellNumber(i, j), setAlign,
1428 UpdateLocal(bv, INIT, true);
1430 UpdateLocal(bv, CELL, true);
1432 case LyXTabular::MULTICOLUMN:
1434 if (sel_row_start != sel_row_end) {
1435 WriteAlert(_("Impossible Operation!"),
1436 _("Multicolumns can only be horizontally."),
1440 // just multicol for one Single Cell
1441 if (!hasSelection()) {
1442 // check wether we are completly in a multicol
1443 if (tabular->IsMultiColumn(actcell)) {
1444 tabular->UnsetMultiColumn(actcell);
1445 UpdateLocal(bv, INIT, true);
1447 tabular->SetMultiColumn(actcell, 1);
1448 UpdateLocal(bv, CELL, true);
1452 // we have a selection so this means we just add all this
1453 // cells to form a multicolumn cell
1457 if (sel_cell_start > sel_cell_end) {
1458 s_start = sel_cell_end;
1459 s_end = sel_cell_start;
1461 s_start = sel_cell_start;
1462 s_end = sel_cell_end;
1464 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1467 sel_cell_end = sel_cell_start;
1468 sel_pos_end = sel_pos_start;
1469 UpdateLocal(bv, INIT, true);
1472 case LyXTabular::SET_ALL_LINES:
1474 case LyXTabular::UNSET_ALL_LINES:
1475 for(i=sel_row_start; i<=sel_row_end; ++i)
1476 for(j=sel_col_start; j<=sel_col_end; ++j)
1477 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1478 UpdateLocal(bv, INIT, true);
1480 case LyXTabular::SET_LONGTABULAR:
1481 tabular->SetLongTabular(true);
1482 UpdateLocal(bv, INIT, true); // because this toggles displayed
1484 case LyXTabular::UNSET_LONGTABULAR:
1485 tabular->SetLongTabular(false);
1486 UpdateLocal(bv, INIT, true); // because this toggles displayed
1488 case LyXTabular::SET_ROTATE_TABULAR:
1489 tabular->SetRotateTabular(true);
1491 case LyXTabular::UNSET_ROTATE_TABULAR:
1492 tabular->SetRotateTabular(false);
1494 case LyXTabular::SET_ROTATE_CELL:
1495 for(i=sel_row_start; i<=sel_row_end; ++i)
1496 for(j=sel_col_start; j<=sel_col_end; ++j)
1497 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1499 case LyXTabular::UNSET_ROTATE_CELL:
1500 for(i = sel_row_start; i <= sel_row_end; ++i)
1501 for(j = sel_col_start; j <= sel_col_end; ++j)
1502 tabular->SetRotateCell(tabular->GetCellNumber(i, j), false);
1504 case LyXTabular::SET_USEBOX:
1506 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1507 if (val == tabular->GetUsebox(actcell))
1508 val = LyXTabular::BOX_NONE;
1509 for(i = sel_row_start; i <= sel_row_end; ++i)
1510 for(j = sel_col_start; j <= sel_col_end; ++j)
1511 tabular->SetUsebox(tabular->GetCellNumber(i, j), val);
1514 case LyXTabular::SET_LTFIRSTHEAD:
1515 tabular->SetLTHead(actcell, true);
1517 case LyXTabular::SET_LTHEAD:
1518 tabular->SetLTHead(actcell, false);
1520 case LyXTabular::SET_LTFOOT:
1521 tabular->SetLTFoot(actcell, false);
1523 case LyXTabular::SET_LTLASTFOOT:
1524 tabular->SetLTFoot(actcell, true);
1526 case LyXTabular::SET_LTNEWPAGE:
1527 what = !tabular->GetLTNewPage(actcell);
1528 tabular->SetLTNewPage(actcell, what);
1534 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1537 // the cursor.pos has to be before the inset so if it isn't now just
1538 // reset the curor pos first!
1539 if (!cellstart(cursor.pos())) {
1540 cursor.pos((cursor.pos() - 1) % 2);
1543 UpdatableInset * inset =
1544 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1545 LyXFont font(LyXFont::ALL_SANE);
1547 x = inset->x() + inset->width(bv, font);
1548 y = inset->descent(bv, font);
1550 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1551 inset_y = cursor.y();
1552 inset->Edit(bv, x - inset_x, y - inset_y, button);
1553 if (!the_locking_inset)
1555 UpdateLocal(bv, CELL, false);
1556 return (the_locking_inset != 0);
1560 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1562 InsetText * inset = tabular->GetCellInset(actcell);
1565 if (!cellstart(cursor.pos())) {
1566 return (((x + top_x) < cursor.x()) &&
1567 ((x + top_x) > (cursor.x() - inset->width(bv,
1568 LyXFont(LyXFont::ALL_SANE)))));
1570 int x2 = cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1571 return ((x1 > x2) &&
1572 (x1 < (x2 + inset->width(bv, LyXFont(LyXFont::ALL_SANE)))));
1577 // This returns paperWidth() if the cell-width is unlimited or the width
1578 // in pixels if we have a pwidth for this cell.
1579 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1581 string const s = tabular->GetPWidth(cell);
1585 return VSpace(s).inPixels(0, 0);
1589 int InsetTabular::getMaxWidth(Painter & pain,
1590 UpdatableInset const * inset) const
1592 int const n = tabular->GetNumberOfCells();
1594 for(; cell < n; ++cell) {
1595 if (tabular->GetCellInset(cell) == inset)
1600 int w = GetMaxWidthOfCell(pain, cell);
1602 // because the inset then subtracts it's top_x and owner->x()
1603 w += (inset->x() - top_x);
1608 void InsetTabular::resizeLyXText(BufferView *) const
1614 LyXText * InsetTabular::getLyXText(BufferView * bv) const
1616 if (the_locking_inset)
1617 return the_locking_inset->getLyXText(bv);
1618 return Inset::getLyXText(bv);
1622 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1624 if (the_locking_inset) {
1625 InsetTabular * i = static_cast<InsetTabular *>
1626 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1628 i->OpenLayoutDialog(bv);
1632 dialogs_ = bv->owner()->getDialogs();
1633 dialogs_->showTabular(const_cast<InsetTabular *>(this));
1637 // functions returns:
1641 // 3 ... toggled off
1643 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1645 int action = LyXTabular::LAST_ACTION;
1646 LyXFunc::func_status status = LyXFunc::OK;
1649 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1650 string const tmp = tabularFeatures[i].feature;
1651 if (tmp == what.substr(0, tmp.length())) {
1652 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1653 // tabularFeatures[i].feature.length())) {
1654 action = tabularFeatures[i].action;
1658 if (action == LyXTabular::LAST_ACTION)
1659 return LyXFunc::Unknown;
1661 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1663 int sel_row_start, sel_row_end;
1667 if (hasSelection()) {
1668 sel_row_start = tabular->row_of_cell(sel_cell_start);
1669 sel_row_end = tabular->row_of_cell(sel_cell_end);
1670 if (sel_row_start > sel_row_end) {
1671 //int tmp = sel_row_start;
1672 //sel_row_start = sel_row_end;
1673 //sel_row_end = tmp;
1674 swap(sel_row_start, sel_row_end);
1677 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1681 case LyXTabular::SET_PWIDTH:
1682 case LyXTabular::SET_MPWIDTH:
1683 case LyXTabular::SET_SPECIAL_COLUMN:
1684 case LyXTabular::SET_SPECIAL_MULTI:
1685 status |= LyXFunc::Disabled;
1688 case LyXTabular::APPEND_ROW:
1689 case LyXTabular::APPEND_COLUMN:
1690 case LyXTabular::DELETE_ROW:
1691 case LyXTabular::DELETE_COLUMN:
1692 case LyXTabular::SET_ALL_LINES:
1693 case LyXTabular::UNSET_ALL_LINES:
1694 status |= LyXFunc::OK;
1697 case LyXTabular::MULTICOLUMN:
1698 if (tabular->IsMultiColumn(actcell))
1699 status |= LyXFunc::ToggleOn;
1701 status |= LyXFunc::ToggleOff;
1703 case LyXTabular::M_TOGGLE_LINE_TOP:
1705 case LyXTabular::TOGGLE_LINE_TOP:
1706 if (tabular->TopLine(actcell, flag))
1707 status |= LyXFunc::ToggleOn;
1709 status |= LyXFunc::ToggleOff;
1711 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1713 case LyXTabular::TOGGLE_LINE_BOTTOM:
1714 if (tabular->BottomLine(actcell, flag))
1715 status |= LyXFunc::ToggleOn;
1717 status |= LyXFunc::ToggleOff;
1719 case LyXTabular::M_TOGGLE_LINE_LEFT:
1721 case LyXTabular::TOGGLE_LINE_LEFT:
1722 if (tabular->LeftLine(actcell, flag))
1723 status |= LyXFunc::ToggleOn;
1725 status |= LyXFunc::ToggleOff;
1727 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1729 case LyXTabular::TOGGLE_LINE_RIGHT:
1730 if (tabular->RightLine(actcell, flag))
1731 status |= LyXFunc::ToggleOn;
1733 status |= LyXFunc::ToggleOff;
1735 case LyXTabular::M_ALIGN_LEFT:
1737 case LyXTabular::ALIGN_LEFT:
1738 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1739 status |= LyXFunc::ToggleOn;
1741 status |= LyXFunc::ToggleOff;
1743 case LyXTabular::M_ALIGN_RIGHT:
1745 case LyXTabular::ALIGN_RIGHT:
1746 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1747 status |= LyXFunc::ToggleOn;
1749 status |= LyXFunc::ToggleOff;
1751 case LyXTabular::M_ALIGN_CENTER:
1753 case LyXTabular::ALIGN_CENTER:
1754 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1755 status |= LyXFunc::ToggleOn;
1757 status |= LyXFunc::ToggleOff;
1759 case LyXTabular::M_VALIGN_TOP:
1761 case LyXTabular::VALIGN_TOP:
1762 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1763 status |= LyXFunc::ToggleOn;
1765 status |= LyXFunc::ToggleOff;
1767 case LyXTabular::M_VALIGN_BOTTOM:
1769 case LyXTabular::VALIGN_BOTTOM:
1770 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1771 status |= LyXFunc::ToggleOn;
1773 status |= LyXFunc::ToggleOff;
1775 case LyXTabular::M_VALIGN_CENTER:
1777 case LyXTabular::VALIGN_CENTER:
1778 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1779 status |= LyXFunc::ToggleOn;
1781 status |= LyXFunc::ToggleOff;
1783 case LyXTabular::SET_LONGTABULAR:
1784 if (tabular->IsLongTabular())
1785 status |= LyXFunc::ToggleOn;
1787 status |= LyXFunc::ToggleOff;
1789 case LyXTabular::UNSET_LONGTABULAR:
1790 if (!tabular->IsLongTabular())
1791 status |= LyXFunc::ToggleOn;
1793 status |= LyXFunc::ToggleOff;
1795 case LyXTabular::SET_ROTATE_TABULAR:
1796 if (tabular->GetRotateTabular())
1797 status |= LyXFunc::ToggleOn;
1799 status |= LyXFunc::ToggleOff;
1801 case LyXTabular::UNSET_ROTATE_TABULAR:
1802 if (!tabular->GetRotateTabular())
1803 status |= LyXFunc::ToggleOn;
1805 status |= LyXFunc::ToggleOff;
1807 case LyXTabular::SET_ROTATE_CELL:
1808 if (tabular->GetRotateCell(actcell))
1809 status |= LyXFunc::ToggleOn;
1811 status |= LyXFunc::ToggleOff;
1813 case LyXTabular::UNSET_ROTATE_CELL:
1814 if (!tabular->GetRotateCell(actcell))
1815 status |= LyXFunc::ToggleOn;
1817 status |= LyXFunc::ToggleOff;
1819 case LyXTabular::SET_USEBOX:
1820 if (strToInt(argument) == tabular->GetUsebox(actcell))
1821 status |= LyXFunc::ToggleOn;
1823 status |= LyXFunc::ToggleOff;
1825 case LyXTabular::SET_LTFIRSTHEAD:
1826 if (tabular->GetRowOfLTHead(actcell, dummy))
1827 status |= LyXFunc::ToggleOn;
1829 status |= LyXFunc::ToggleOff;
1831 case LyXTabular::SET_LTHEAD:
1832 if (tabular->GetRowOfLTHead(actcell, dummy))
1833 status |= LyXFunc::ToggleOn;
1835 status |= LyXFunc::ToggleOff;
1837 case LyXTabular::SET_LTFOOT:
1838 if (tabular->GetRowOfLTFoot(actcell, dummy))
1839 status |= LyXFunc::ToggleOn;
1841 status |= LyXFunc::ToggleOff;
1843 case LyXTabular::SET_LTLASTFOOT:
1844 if (tabular->GetRowOfLTFoot(actcell, dummy))
1845 status |= LyXFunc::ToggleOn;
1847 status |= LyXFunc::ToggleOff;
1849 case LyXTabular::SET_LTNEWPAGE:
1850 if (tabular->GetLTNewPage(actcell))
1851 status |= LyXFunc::ToggleOn;
1853 status |= LyXFunc::ToggleOff;
1856 status = LyXFunc::Disabled;
1863 bool InsetTabular::copySelection()
1865 if (!hasSelection())
1867 delete paste_tabular;
1869 int sel_col_start, sel_col_end;
1870 int sel_row_start, sel_row_end;
1872 sel_col_start = tabular->column_of_cell(sel_cell_start);
1873 sel_col_end = tabular->column_of_cell(sel_cell_end);
1874 if (sel_col_start > sel_col_end) {
1875 sel_col_start = sel_col_end;
1876 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1878 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1880 int columns = sel_col_end - sel_col_start + 1;
1882 sel_row_start = tabular->row_of_cell(sel_cell_start);
1883 sel_row_end = tabular->row_of_cell(sel_cell_end);
1884 if (sel_row_start > sel_row_end) {
1885 //int tmp tmp = sel_row_start;
1886 //sel_row_start = sel_row_end;
1887 //sel_row_end = tmp;
1888 swap(sel_row_start, sel_row_end);
1890 int rows = sel_row_end - sel_row_start + 1;
1892 paste_tabular = new LyXTabular(this, rows, columns);
1894 if (sel_cell_start > sel_cell_end) {
1895 //int tmp = sel_cell_start;
1896 //sel_cell_start = sel_cell_end;
1897 //sel_cell_end = tmp;
1898 swap(sel_cell_start, sel_cell_end);
1900 for(int i = sel_cell_start, j = 0; i <= sel_cell_end; ++i, ++j) {
1901 while(paste_tabular->row_of_cell(j) <
1902 (tabular->row_of_cell(i)-sel_row_start)) {
1905 while(paste_tabular->row_of_cell(j) >
1906 (tabular->row_of_cell(i)-sel_row_start)) {
1909 *(paste_tabular->GetCellInset(j)) = *(tabular->GetCellInset(i));
1915 bool InsetTabular::pasteSelection(BufferView * bv)
1919 for(int j=0, i=actcell; j<paste_tabular->GetNumberOfCells(); ++j,++i) {
1920 while (paste_tabular->row_of_cell(j) > tabular->row_of_cell(i)-actrow)
1922 if (tabular->GetNumberOfCells() <= i)
1924 while (paste_tabular->row_of_cell(j) < tabular->row_of_cell(i)-actrow)
1926 if (paste_tabular->GetNumberOfCells() <= j)
1928 *(tabular->GetCellInset(i)) = *(paste_tabular->GetCellInset(j));
1929 tabular->GetCellInset(i)->setOwner(this);
1930 tabular->GetCellInset(i)->deleteLyXText(bv);
1936 bool InsetTabular::cutSelection()
1938 if (!hasSelection())
1941 int sel_col_start, sel_col_end;
1942 int sel_row_start, sel_row_end;
1944 sel_col_start = tabular->column_of_cell(sel_cell_start);
1945 sel_col_end = tabular->column_of_cell(sel_cell_end);
1946 if (sel_col_start > sel_col_end) {
1947 sel_col_start = sel_col_end;
1948 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1950 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1952 sel_row_start = tabular->row_of_cell(sel_cell_start);
1953 sel_row_end = tabular->row_of_cell(sel_cell_end);
1954 if (sel_row_start > sel_row_end) {
1955 //int tmp = sel_row_start;
1956 //sel_row_start = sel_row_end;
1957 //sel_row_end = tmp;
1958 swap(sel_row_start, sel_row_end);
1960 if (sel_cell_start > sel_cell_end) {
1961 //int tmp = sel_cell_start;
1962 //sel_cell_start = sel_cell_end;
1963 //sel_cell_end = tmp;
1964 swap(sel_cell_start, sel_cell_end);
1966 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1967 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1968 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();