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;
49 struct tabular_features {
54 //static tabular_features * tabularFeatures = 0;
56 static tabular_features tabularFeatures[] =
58 { LyXTabular::APPEND_ROW, "append-row" },
59 { LyXTabular::APPEND_COLUMN, "append-column" },
60 { LyXTabular::DELETE_ROW, "delete-row" },
61 { LyXTabular::DELETE_COLUMN, "delete-column" },
62 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
63 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
64 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
65 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
66 { LyXTabular::ALIGN_LEFT, "align-left" },
67 { LyXTabular::ALIGN_RIGHT, "align-right" },
68 { LyXTabular::ALIGN_CENTER, "align-center" },
69 { LyXTabular::VALIGN_TOP, "valign-top" },
70 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
71 { LyXTabular::VALIGN_CENTER, "valign-center" },
72 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
73 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
74 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
75 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
76 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
77 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
78 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
79 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
80 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
81 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
82 { LyXTabular::DELETE_TABULAR, "delete-tabular" },
83 { LyXTabular::MULTICOLUMN, "multicolumn" },
84 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
85 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
86 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
87 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
88 { LyXTabular::SET_PWIDTH, "set-pwidth" },
89 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
90 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
91 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
92 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
93 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
94 { LyXTabular::SET_USEBOX, "set-usebox" },
95 { LyXTabular::SET_LTHEAD, "set-lthead" },
96 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
97 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
98 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
99 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
100 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
101 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
102 { LyXTabular::LAST_ACTION, "" }
105 //#define cellstart(p) ((p % 2) == 0)
107 bool cellstart(LyXParagraph::size_type p)
109 return ((p % 2) == 0);
113 InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
120 tabular = new LyXTabular(this, rows,columns);
121 // for now make it always display as display() inset
123 the_locking_inset = 0;
124 locked = no_selection = cursor_visible = false;
129 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
136 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
139 tabular = new LyXTabular(this, *(tab.tabular));
140 the_locking_inset = 0;
141 locked = no_selection = cursor_visible = false;
146 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
153 InsetTabular::~InsetTabular()
157 dialogs_->hideTabular(this);
161 Inset * InsetTabular::Clone() const
163 InsetTabular * t = new InsetTabular(*this, buffer);
165 t->tabular = tabular->Clone(t);
170 void InsetTabular::Write(Buffer const * buf, ostream & os) const
172 os << " Tabular" << endl;
173 tabular->Write(buf, os);
177 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
179 bool old_format = (lex.GetString() == "\\LyXTable");
184 tabular = new LyXTabular(buf, this, lex);
192 token = lex.GetString();
193 while (lex.IsOK() && (token != "\\end_inset")) {
195 token = lex.GetString();
197 if (token != "\\end_inset") {
198 lex.printError("Missing \\end_inset at this point. "
204 int InsetTabular::ascent(BufferView *, LyXFont const &) const
206 return tabular->GetAscentOfRow(0);
210 int InsetTabular::descent(BufferView *, LyXFont const &) const
212 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
216 int InsetTabular::width(BufferView *, LyXFont const &) const
218 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
222 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
223 float & x, bool cleared) const
225 Painter & pain = bv->painter();
230 UpdatableInset::draw(bv,font,baseline,x,cleared);
231 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
232 (top_x != int(x)) || (top_baseline != baseline))) {
233 int h = ascent(bv, font) + descent(bv, font);
234 int tx = display()||!owner()? 0:top_x;
235 int w = tx? width(bv, font):pain.paperWidth();
236 int ty = baseline - ascent(bv, font);
240 if ((ty + h) > pain.paperHeight())
241 h = pain.paperHeight();
242 if ((top_x + w) > pain.paperWidth())
243 w = pain.paperWidth();
244 pain.fillRectangle(tx, ty, w, h);
249 top_baseline = baseline;
250 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
253 x += ADD_TO_TABULAR_WIDTH;
254 if (cleared || (need_update == FULL) || (need_update == CELL)) {
255 for(i=0;i<tabular->rows();++i) {
257 dodraw = ((baseline+tabular->GetDescentOfRow(i)) > 0) &&
258 (baseline-tabular->GetAscentOfRow(i)) < pain.paperHeight();
259 for(j=0;j<tabular->columns();++j) {
260 if (tabular->IsPartOfMultiColumn(i,j))
262 cx = nx + tabular->GetBeginningOfTextInCell(cell);
264 DrawCellSelection(pain, nx, baseline, i, j, cell);
265 if (dodraw && !cleared && locked && the_locking_inset) {
266 if (the_locking_inset == tabular->GetCellInset(cell)) {
267 LyXText::text_status st = bv->text->status;
269 bv->text->status = st;
270 if (need_update == CELL) {
271 // clear before the inset
274 baseline - tabular->GetAscentOfRow(i)+1,
276 tabular->GetAscentOfRow(i) +
277 tabular->GetDescentOfRow(i) - 1);
278 // clear behind the inset
280 cx + the_locking_inset->width(bv,font) + 1,
281 baseline - tabular->GetAscentOfRow(i)+1,
282 tabular->GetWidthOfColumn(cell) -
283 tabular->GetBeginningOfTextInCell(cell) -
284 the_locking_inset->width(bv,font) - 1,
285 tabular->GetAscentOfRow(i) +
286 tabular->GetDescentOfRow(i) - 1);
288 tabular->GetCellInset(cell)->draw(
289 bv, font, baseline, cx, false);
290 } while(bv->text->status == LyXText::CHANGED_IN_DRAW);
293 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
295 DrawCellLines(pain, nx, baseline, i, cell);
297 nx += tabular->GetWidthOfColumn(cell);
300 baseline += tabular->GetDescentOfRow(i) +
301 tabular->GetAscentOfRow(i+1)+
302 tabular->GetAdditionalHeight(cell+1);
305 x -= ADD_TO_TABULAR_WIDTH;
306 x += width(bv, font);
307 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
314 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
315 int row, int cell) const
317 int x2 = x + tabular->GetWidthOfColumn(cell);
320 if (!tabular->TopAlreadyDrawed(cell)) {
321 on_off = !tabular->TopLine(cell);
322 pain.line(x, baseline - tabular->GetAscentOfRow(row),
323 x2, baseline - tabular->GetAscentOfRow(row),
324 on_off ? LColor::tabularonoffline:LColor::tabularline,
325 on_off ? Painter::line_onoffdash:Painter::line_solid);
327 on_off = !tabular->BottomLine(cell);
328 pain.line(x,baseline + tabular->GetDescentOfRow(row),
329 x2, baseline + tabular->GetDescentOfRow(row),
330 on_off ? LColor::tabularonoffline:LColor::tabularline,
331 on_off ? Painter::line_onoffdash:Painter::line_solid);
332 if (!tabular->LeftAlreadyDrawed(cell)) {
333 on_off = !tabular->LeftLine(cell);
334 pain.line(x, baseline - tabular->GetAscentOfRow(row),
335 x, baseline + tabular->GetDescentOfRow(row),
336 on_off ? LColor::tabularonoffline:LColor::tabularline,
337 on_off ? Painter::line_onoffdash:Painter::line_solid);
339 on_off = !tabular->RightLine(cell);
340 pain.line(x2 - tabular->GetAdditionalWidth(cell),
341 baseline - tabular->GetAscentOfRow(row),
342 x2 - tabular->GetAdditionalWidth(cell),
343 baseline + tabular->GetDescentOfRow(row),
344 on_off ? LColor::tabularonoffline:LColor::tabularline,
345 on_off ? Painter::line_onoffdash:Painter::line_solid);
349 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
350 int row, int column, int cell) const
352 int cs = tabular->column_of_cell(sel_cell_start);
353 int ce = tabular->column_of_cell(sel_cell_end);
356 cs = tabular->column_of_cell(sel_cell_end);
358 ce = tabular->right_column_of_cell(sel_cell_end);
361 int rs = tabular->row_of_cell(sel_cell_start);
362 int re = tabular->row_of_cell(sel_cell_end);
363 if (rs > re) swap(rs, re);
365 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
366 int w = tabular->GetWidthOfColumn(cell);
367 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
368 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
369 w, h, LColor::selection);
374 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
378 calculate_dimensions_of_cells(bv, font, true);
380 owner()->update(bv, font, true);
383 if (the_locking_inset)
384 the_locking_inset->update(bv, font, reinit);
385 switch(need_update) {
389 if (calculate_dimensions_of_cells(bv, font, false))
401 char const * InsetTabular::EditMessage() const
403 return _("Opened Tabular Inset");
407 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
409 UpdatableInset::Edit(bv, x, y, button);
411 if (!bv->lockInset(this)) {
412 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
416 the_locking_inset = 0;
417 inset_pos = inset_x = inset_y = 0;
419 sel_pos_start = sel_pos_end = cursor.pos();
420 sel_cell_start = sel_cell_end = actcell;
421 bv->text->FinishUndo();
422 if (InsetHit(bv, x, y)) {
423 ActivateCellInset(bv, x, y, button);
425 UpdateLocal(bv, NONE, false);
426 // bv->getOwner()->getPopups().updateFormTabular();
430 void InsetTabular::InsetUnlock(BufferView * bv)
432 if (the_locking_inset) {
433 the_locking_inset->InsetUnlock(bv);
434 the_locking_inset = 0;
437 no_selection = false;
440 if (scroll() || hasSelection()) {
442 scroll(bv, (float)0.0);
444 sel_pos_start = sel_pos_end = 0;
445 sel_cell_start = sel_cell_end = 0;
447 UpdateLocal(bv, FULL, false);
452 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
453 bool mark_dirty) const
456 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
457 if (locked && (what != NONE))
462 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
464 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
468 if (inset == tabular->GetCellInset(actcell)) {
469 lyxerr[Debug::INSETS] << "OK" << endl;
470 the_locking_inset = tabular->GetCellInset(actcell);
472 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
473 inset_y = cursor.y();
474 inset_pos = cursor.pos();
476 } else if (the_locking_inset && (the_locking_inset == inset)) {
477 if (cursor.pos() == inset_pos) {
478 lyxerr[Debug::INSETS] << "OK" << endl;
480 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
481 inset_y = cursor.y();
483 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
485 } else if (the_locking_inset) {
486 lyxerr[Debug::INSETS] << "MAYBE" << endl;
487 return the_locking_inset->LockInsetInInset(bv, inset);
489 lyxerr[Debug::INSETS] << "NOT OK" << endl;
494 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
497 if (!the_locking_inset)
499 if (the_locking_inset == inset) {
500 the_locking_inset->InsetUnlock(bv);
501 the_locking_inset = 0;
503 moveRight(bv, false);
504 UpdateLocal(bv, CELL, false);
507 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
508 if ((inset->LyxCode() == TABULAR_CODE) &&
509 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
511 dialogs_ = bv->owner()->getDialogs();
512 dialogs_->updateTabular(const_cast<InsetTabular *>(this));
521 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
523 if (!the_locking_inset)
525 if (the_locking_inset != inset)
526 return the_locking_inset->UpdateInsetInInset(bv, inset);
527 UpdateLocal(bv, CELL, false);
532 int InsetTabular::InsetInInsetY()
534 if (!the_locking_inset)
537 return (inset_y + the_locking_inset->InsetInInsetY());
541 UpdatableInset * InsetTabular::GetLockingInset()
543 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
547 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
551 if (the_locking_inset)
552 return the_locking_inset->GetFirstLockingInsetOfType(c);
557 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
559 if (the_locking_inset)
560 return the_locking_inset->InsertInset(bv, inset);
565 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
567 if (hasSelection()) {
568 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
569 UpdateLocal(bv, SELECTION, false);
571 no_selection = false;
579 UpdateLocal(bv, NONE, false);
580 sel_pos_start = sel_pos_end = cursor.pos();
581 sel_cell_start = sel_cell_end = actcell;
583 bool inset_hit = InsetHit(bv, x, y);
585 if ((ocell == actcell) && the_locking_inset && inset_hit) {
586 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
588 } else if (the_locking_inset) {
589 the_locking_inset->InsetUnlock(bv);
591 the_locking_inset = 0;
592 if (inset_hit && bv->the_locking_inset) {
593 ActivateCellInset(bv, x, y, button);
594 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
601 void InsetTabular::InsetButtonRelease(BufferView * bv,
602 int x, int y, int button)
605 if (the_locking_inset) {
607 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
608 i->InsetButtonRelease(bv, x, y, button);
612 dialogs_ = bv->owner()->getDialogs();
613 dialogs_->showTabular(this);
616 if (the_locking_inset) {
617 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
620 no_selection = false;
624 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
626 if (the_locking_inset) {
627 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
628 y - inset_y, button);
633 int old_pos = sel_pos_end;
634 int old_cell = actcell;
637 sel_pos_end = cursor.pos();
638 sel_cell_end = actcell;
639 if ((sel_cell_end != old_cell) || (old_pos != sel_pos_end))
640 UpdateLocal(bv, SELECTION, false);
643 no_selection = false;
647 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
649 if (the_locking_inset) {
650 the_locking_inset->InsetKeyPress(xke);
656 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
659 UpdatableInset::RESULT
662 no_selection = false;
663 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
664 || (result == DISPATCHED_NOUPDATE)) {
670 if ((action < 0) && arg.empty())
673 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
674 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
676 if (the_locking_inset) {
677 result=the_locking_inset->LocalDispatch(bv, action, arg);
678 if (result == DISPATCHED_NOUPDATE)
680 else if (result == DISPATCHED) {
681 the_locking_inset->ToggleInsetCursor(bv);
682 UpdateLocal(bv, CELL, false);
683 the_locking_inset->ToggleInsetCursor(bv);
685 } else if (result == FINISHED) {
686 if ((action == LFUN_RIGHT) || (action == -1)) {
687 cursor.pos(inset_pos + 1);
690 sel_pos_start = sel_pos_end = cursor.pos();
691 sel_cell_start = sel_cell_end = actcell;
698 bool hs = hasSelection();
702 // Normal chars not handled here
705 // --- Cursor Movements ---------------------------------------------
707 if (tabular->IsLastCellInRow(actcell) && !cellstart(cursor.pos()))
709 moveRight(bv, false);
710 sel_pos_end = cursor.pos();
711 if (!cellstart(cursor.pos())) {
712 if (tabular->right_column_of_cell(sel_cell_start) >
713 tabular->right_column_of_cell(actcell))
714 sel_cell_end = actcell+1;
716 sel_cell_end = actcell;
718 UpdateLocal(bv, SELECTION, false);
721 result = moveRight(bv);
722 sel_pos_start = sel_pos_end = cursor.pos();
723 sel_cell_start = sel_cell_end = actcell;
725 UpdateLocal(bv, SELECTION, false);
728 if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos()))
731 sel_pos_end = cursor.pos();
732 if (cellstart(cursor.pos())) {
733 if (tabular->column_of_cell(sel_cell_start) >=
734 tabular->column_of_cell(actcell))
735 sel_cell_end = actcell;
737 sel_cell_end = actcell-1;
739 UpdateLocal(bv, SELECTION, false);
742 result = moveLeft(bv);
743 sel_pos_start = sel_pos_end = cursor.pos();
744 sel_cell_start = sel_cell_end = actcell;
746 UpdateLocal(bv, SELECTION, false);
752 sel_pos_end = cursor.pos();
753 if ((ocell == sel_cell_end) ||
754 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
755 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
757 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
758 UpdateLocal(bv, SELECTION, false);
762 result= moveDown(bv);
763 sel_pos_start = sel_pos_end = cursor.pos();
764 sel_cell_start = sel_cell_end = actcell;
766 UpdateLocal(bv, SELECTION, false);
772 sel_pos_end = cursor.pos();
773 if ((ocell == sel_cell_end) ||
774 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
775 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
777 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
778 UpdateLocal(bv, SELECTION, false);
783 sel_pos_start = sel_pos_end = cursor.pos();
784 sel_cell_start = sel_cell_end = actcell;
786 UpdateLocal(bv, SELECTION, false);
798 if (the_locking_inset) {
799 UnlockInsetInInset(bv, the_locking_inset);
800 the_locking_inset = 0;
802 if (action == LFUN_TAB)
806 sel_pos_start = sel_pos_end = cursor.pos();
807 sel_cell_start = sel_cell_end = actcell;
809 UpdateLocal(bv, SELECTION, false);
811 case LFUN_LAYOUT_TABLE:
813 dialogs_ = bv->owner()->getDialogs();
814 dialogs_->showTabular(this);
817 case LFUN_TABULAR_FEATURE:
818 if (!TabularFeatures(bv, arg))
819 result = UNDISPATCHED;
822 if (!copySelection())
824 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
826 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
827 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
829 bv->text->cursor.par()->previous,
830 bv->text->cursor.par()->next
834 UpdateLocal(bv, INIT, true);
839 bv->text->FinishUndo();
843 if (!hasPasteBuffer())
845 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
847 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
848 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
850 bv->text->cursor.par()->previous,
851 bv->text->cursor.par()->next
855 UpdateLocal(bv, INIT, true);
858 result = UNDISPATCHED;
861 if (result!=FINISHED) {
862 if (!the_locking_inset) {
864 if (ocell != actcell)
865 bview->getOwner()->getPopups().updateFormTabular();
870 bv->unlockInset(this);
875 int InsetTabular::Latex(Buffer const * buf, ostream & os,
876 bool fragile, bool fp) const
878 return tabular->Latex(buf, os, fragile, fp);
882 int InsetTabular::Ascii(Buffer const *, ostream &) const
888 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
894 int InsetTabular::DocBook(Buffer const *, ostream &) const
900 void InsetTabular::Validate(LaTeXFeatures & features) const
902 tabular->Validate(features);
906 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
907 LyXFont const & font,
913 bool changed = false;
915 for(int i = 0; i < tabular->rows(); ++i) {
916 maxAsc = maxDesc = 0;
917 for(int j= 0; j < tabular->columns(); ++j) {
918 if (tabular->IsPartOfMultiColumn(i,j))
921 inset = tabular->GetCellInset(cell);
923 inset->update(bv, font, false);
924 maxAsc = max(maxAsc, inset->ascent(bv, font));
925 maxDesc = max(maxDesc, inset->descent(bv, font));
926 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
928 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
929 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
935 void InsetTabular::GetCursorPos(BufferView *, int & x, int & y) const
937 x = cursor.x() - top_x;
942 void InsetTabular::ToggleInsetCursor(BufferView * bv)
944 if (the_locking_inset) {
945 the_locking_inset->ToggleInsetCursor(bv);
949 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
951 int asc = lyxfont::maxAscent(font);
952 int desc = lyxfont::maxDescent(font);
955 bv->hideLockedInsetCursor();
957 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
958 cursor_visible = !cursor_visible;
962 void InsetTabular::ShowInsetCursor(BufferView * bv)
964 if (!cursor_visible) {
965 LyXFont font; // = GetFont(par, cursor.pos);
967 int asc = lyxfont::maxAscent(font);
968 int desc = lyxfont::maxDescent(font);
969 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
970 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
971 cursor_visible = true;
976 void InsetTabular::HideInsetCursor(BufferView * bv)
978 if (cursor_visible) {
979 bv->hideLockedInsetCursor();
980 cursor_visible = false;
982 // if (cursor_visible)
983 // ToggleInsetCursor(bv);
987 void InsetTabular::setPos(BufferView * bv, int x, int y) const
992 actcell = actrow = actcol = 0;
993 int ly = tabular->GetDescentOfRow(actrow);
995 // first search the right row
996 while((ly < y) && (actrow < tabular->rows())) {
997 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
998 tabular->GetAscentOfRow(actrow+1) +
999 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1002 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1004 actcell = tabular->GetCellNumber(actrow, actcol);
1006 // now search the right column
1007 int lx = tabular->GetWidthOfColumn(actcell) -
1008 tabular->GetAdditionalWidth(actcell);
1009 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
1010 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1011 tabular->GetAdditionalWidth(actcell - 1));
1014 if ((lx - (tabular->GetWidthOfColumn(actcell)/2)) < x) {
1015 cursor.x(lx + top_x - 2);
1018 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1024 int InsetTabular::getCellXPos(int cell) const
1028 for(c=cell;!tabular->IsFirstCellInRow(c);--c)
1030 int lx = tabular->GetWidthOfColumn(cell);
1031 for(; (c < cell); ++c) {
1032 lx += tabular->GetWidthOfColumn(c);
1034 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1038 void InsetTabular::resetPos(BufferView * bv) const
1042 actcol = tabular->column_of_cell(actcell);
1047 for(; (cell<actcell) && !tabular->IsLastRow(cell); ++cell) {
1048 if (tabular->IsLastCellInRow(cell)) {
1049 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1050 tabular->GetAscentOfRow(actrow + 1) +
1051 tabular->GetAdditionalHeight(cell + 1));
1055 static int offset = ADD_TO_TABULAR_WIDTH + 2;
1056 cursor.x(getCellXPos(actcell) + offset);
1057 if (((cursor.x() - offset) > 20) &&
1058 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1059 (bv->workWidth()-20)))
1061 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1062 UpdateLocal(bv, FULL, false);
1063 } else if ((cursor.x() - offset) < 20) {
1064 scroll(bv, 20 - cursor.x() + offset);
1065 UpdateLocal(bv, FULL, false);
1066 } else if (!cellstart(cursor.pos())) {
1067 LyXFont font(LyXFont::ALL_SANE);
1068 cursor.x(cursor.x() + tabular->GetCellInset(actcell)->width(bv,font) +
1069 tabular->GetBeginningOfTextInCell(actcell));
1071 if ((!the_locking_inset ||
1072 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1073 (actcell != oldcell)) {
1074 dialogs_ = bv->owner()->getDialogs();
1075 dialogs_->updateTabular(const_cast<InsetTabular *>(this));
1081 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1083 if (!cellstart(cursor.pos())) {
1084 if (tabular->IsLastCell(actcell))
1087 cursor.pos((cursor.pos() + 1) % 2);
1089 if (ActivateCellInset(bv))
1091 } else { // before the inset
1092 cursor.pos((cursor.pos() + 1) % 2);
1095 return DISPATCHED_NOUPDATE;
1099 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1101 if (!cursor.pos()) {
1106 cursor.pos((cursor.pos() - 1) % 2);
1107 if (!cellstart(cursor.pos())) {
1109 } else if (lock) { // behind the inset
1110 if (ActivateCellInset(bv, 0, 0, 0, true))
1114 return DISPATCHED_NOUPDATE;
1118 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv)
1120 int ocell = actcell;
1121 actcell = tabular->GetCellAbove(actcell);
1122 if (actcell == ocell) // we moved out of the inset
1125 return DISPATCHED_NOUPDATE;
1129 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv)
1131 int ocell = actcell;
1132 actcell = tabular->GetCellBelow(actcell);
1133 if (actcell == ocell) // we moved out of the inset
1136 return DISPATCHED_NOUPDATE;
1140 bool InsetTabular::moveNextCell(BufferView * bv)
1142 if (tabular->IsLastCell(actcell))
1145 cursor.pos((cursor.pos() + 1) % 2);
1146 if (!cellstart(cursor.pos()))
1147 cursor.pos((cursor.pos() + 1) % 2);
1153 bool InsetTabular::movePrevCell(BufferView * bv)
1155 if (!actcell) // first cell
1158 cursor.pos((cursor.pos() - 1) % 2);
1159 if (cellstart(cursor.pos()))
1160 cursor.pos((cursor.pos() - 1) % 2);
1166 bool InsetTabular::Delete()
1172 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1174 if (the_locking_inset)
1175 the_locking_inset->SetFont(bv, font, tall);
1179 bool InsetTabular::TabularFeatures(BufferView * bv, string what)
1181 int action = LyXTabular::LAST_ACTION;
1185 for(i=0; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1186 if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1187 tabularFeatures[i].feature.length())) {
1188 action = tabularFeatures[i].action;
1192 if (action == LyXTabular::LAST_ACTION)
1195 val = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1196 TabularFeatures(bv, action, val);
1201 void InsetTabular::TabularFeatures(BufferView * bv, int feature, string value)
1210 setAlign = LYX_ALIGN_LEFT,
1216 case LyXTabular::M_ALIGN_LEFT:
1217 case LyXTabular::ALIGN_LEFT:
1218 setAlign=LYX_ALIGN_LEFT;
1220 case LyXTabular::M_ALIGN_RIGHT:
1221 case LyXTabular::ALIGN_RIGHT:
1222 setAlign=LYX_ALIGN_RIGHT;
1224 case LyXTabular::M_ALIGN_CENTER:
1225 case LyXTabular::ALIGN_CENTER:
1226 setAlign=LYX_ALIGN_CENTER;
1228 case LyXTabular::M_VALIGN_TOP:
1229 case LyXTabular::VALIGN_TOP:
1230 setAlign=LyXTabular::LYX_VALIGN_TOP;
1232 case LyXTabular::M_VALIGN_BOTTOM:
1233 case LyXTabular::VALIGN_BOTTOM:
1234 setAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1236 case LyXTabular::M_VALIGN_CENTER:
1237 case LyXTabular::VALIGN_CENTER:
1238 setAlign=LyXTabular::LYX_VALIGN_CENTER;
1243 if (hasSelection()) {
1245 sel_col_start = tabular->column_of_cell(sel_cell_start);
1246 sel_col_end = tabular->column_of_cell(sel_cell_end);
1247 if (sel_col_start > sel_col_end) {
1248 sel_col_end = sel_col_start;
1249 sel_col_start = tabular->column_of_cell(sel_cell_end);
1251 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1254 sel_row_start = tabular->row_of_cell(sel_cell_start);
1255 sel_row_end = tabular->row_of_cell(sel_cell_end);
1256 if (sel_row_start > sel_row_end) {
1257 tmp = sel_row_start;
1258 sel_row_start = sel_row_end;
1262 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1263 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1265 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1267 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1268 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1270 bv->text->cursor.par()->previous,
1271 bv->text->cursor.par()->next
1275 int row = tabular->row_of_cell(actcell);
1276 int column = tabular->column_of_cell(actcell);
1280 case LyXTabular::SET_PWIDTH:
1282 bool update = (tabular->GetColumnPWidth(actcell) != value);
1283 tabular->SetColumnPWidth(actcell,value);
1285 for (int i=0; i < tabular->rows(); ++i) {
1286 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1289 UpdateLocal(bv, INIT, true);
1293 case LyXTabular::SET_MPWIDTH:
1295 bool update = (tabular->GetPWidth(actcell) != value);
1296 tabular->SetMColumnPWidth(actcell,value);
1298 for (int i=0; i < tabular->rows(); ++i) {
1299 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1302 UpdateLocal(bv, INIT, true);
1306 case LyXTabular::SET_SPECIAL_COLUMN:
1307 case LyXTabular::SET_SPECIAL_MULTI:
1308 tabular->SetAlignSpecial(actcell,value,feature);
1310 case LyXTabular::APPEND_ROW:
1311 // append the row into the tabular
1312 UnlockInsetInInset(bv, the_locking_inset);
1313 tabular->AppendRow(actcell);
1314 UpdateLocal(bv, INIT, true);
1316 case LyXTabular::APPEND_COLUMN:
1317 // append the column into the tabular
1318 tabular->AppendColumn(actcell);
1319 actcell = tabular->GetCellNumber(row, column);
1320 UpdateLocal(bv, INIT, true);
1322 case LyXTabular::DELETE_ROW:
1323 tabular->DeleteRow(tabular->row_of_cell(actcell));
1324 if ((row+1) > tabular->rows())
1326 actcell = tabular->GetCellNumber(row, column);
1327 UpdateLocal(bv, INIT, true);
1329 case LyXTabular::DELETE_COLUMN:
1330 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1331 if ((column+1) > tabular->columns())
1333 actcell = tabular->GetCellNumber(row, column);
1334 UpdateLocal(bv, INIT, true);
1336 case LyXTabular::M_TOGGLE_LINE_TOP:
1338 case LyXTabular::TOGGLE_LINE_TOP:
1339 lineSet = !tabular->TopLine(actcell, flag);
1340 for(i=sel_row_start; i<=sel_row_end; ++i)
1341 for(j=sel_col_start; j<=sel_col_end; ++j)
1342 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1343 UpdateLocal(bv, INIT, true);
1346 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1348 case LyXTabular::TOGGLE_LINE_BOTTOM:
1349 lineSet = !tabular->BottomLine(actcell, flag);
1350 for(i=sel_row_start; i<=sel_row_end; ++i)
1351 for(j=sel_col_start; j<=sel_col_end; ++j)
1352 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1354 UpdateLocal(bv, INIT, true);
1357 case LyXTabular::M_TOGGLE_LINE_LEFT:
1359 case LyXTabular::TOGGLE_LINE_LEFT:
1360 lineSet = !tabular->LeftLine(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->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1365 UpdateLocal(bv, INIT, true);
1368 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1370 case LyXTabular::TOGGLE_LINE_RIGHT:
1371 lineSet = !tabular->RightLine(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->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1376 UpdateLocal(bv, INIT, true);
1378 case LyXTabular::M_ALIGN_LEFT:
1379 case LyXTabular::M_ALIGN_RIGHT:
1380 case LyXTabular::M_ALIGN_CENTER:
1382 case LyXTabular::ALIGN_LEFT:
1383 case LyXTabular::ALIGN_RIGHT:
1384 case LyXTabular::ALIGN_CENTER:
1385 for(i=sel_row_start; i<=sel_row_end; ++i)
1386 for(j=sel_col_start; j<=sel_col_end; ++j)
1387 tabular->SetAlignment(tabular->GetCellNumber(i,j),setAlign,
1390 UpdateLocal(bv, INIT, true);
1392 UpdateLocal(bv, CELL, true);
1394 case LyXTabular::M_VALIGN_TOP:
1395 case LyXTabular::M_VALIGN_BOTTOM:
1396 case LyXTabular::M_VALIGN_CENTER:
1398 case LyXTabular::VALIGN_TOP:
1399 case LyXTabular::VALIGN_BOTTOM:
1400 case LyXTabular::VALIGN_CENTER:
1401 for(i=sel_row_start; i<=sel_row_end; ++i)
1402 for(j=sel_col_start; j<=sel_col_end; ++j)
1403 tabular->SetVAlignment(tabular->GetCellNumber(i,j), setAlign,
1406 UpdateLocal(bv, INIT, true);
1408 UpdateLocal(bv, CELL, true);
1410 case LyXTabular::MULTICOLUMN:
1412 if (sel_row_start != sel_row_end) {
1413 WriteAlert(_("Impossible Operation!"),
1414 _("Multicolumns can only be horizontally."),
1418 // just multicol for one Single Cell
1419 if (!hasSelection()) {
1420 // check wether we are completly in a multicol
1421 if (tabular->IsMultiColumn(actcell)) {
1422 tabular->UnsetMultiColumn(actcell);
1423 UpdateLocal(bv, INIT, true);
1425 tabular->SetMultiColumn(actcell, 1);
1426 UpdateLocal(bv, CELL, true);
1430 // we have a selection so this means we just add all this
1431 // cells to form a multicolumn cell
1435 if (sel_cell_start > sel_cell_end) {
1436 s_start = sel_cell_end;
1437 s_end = sel_cell_start;
1439 s_start = sel_cell_start;
1440 s_end = sel_cell_end;
1442 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1445 sel_cell_end = sel_cell_start;
1446 sel_pos_end = sel_pos_start;
1447 UpdateLocal(bv, INIT, true);
1450 case LyXTabular::SET_ALL_LINES:
1452 case LyXTabular::UNSET_ALL_LINES:
1453 for(i=sel_row_start; i<=sel_row_end; ++i)
1454 for(j=sel_col_start; j<=sel_col_end; ++j)
1455 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1456 UpdateLocal(bv, INIT, true);
1458 case LyXTabular::SET_LONGTABULAR:
1459 tabular->SetLongTabular(true);
1460 UpdateLocal(bv, INIT, true); // because this toggles displayed
1462 case LyXTabular::UNSET_LONGTABULAR:
1463 tabular->SetLongTabular(false);
1464 UpdateLocal(bv, INIT, true); // because this toggles displayed
1466 case LyXTabular::SET_ROTATE_TABULAR:
1467 tabular->SetRotateTabular(true);
1469 case LyXTabular::UNSET_ROTATE_TABULAR:
1470 tabular->SetRotateTabular(false);
1472 case LyXTabular::SET_ROTATE_CELL:
1473 for(i=sel_row_start; i<=sel_row_end; ++i)
1474 for(j=sel_col_start; j<=sel_col_end; ++j)
1475 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1477 case LyXTabular::UNSET_ROTATE_CELL:
1478 for(i=sel_row_start; i<=sel_row_end; ++i)
1479 for(j=sel_col_start; j<=sel_col_end; ++j)
1480 tabular->SetRotateCell(tabular->GetCellNumber(i,j),false);
1482 case LyXTabular::SET_USEBOX:
1484 LyXTabular::BoxType val = static_cast<LyXTabular::BoxType>
1486 if (val == tabular->GetUsebox(actcell))
1487 val = LyXTabular::BOX_NONE;
1488 for(i=sel_row_start; i<=sel_row_end; ++i)
1489 for(j=sel_col_start; j<=sel_col_end; ++j)
1490 tabular->SetUsebox(tabular->GetCellNumber(i,j),val);
1493 case LyXTabular::SET_LTFIRSTHEAD:
1494 tabular->SetLTHead(actcell,true);
1496 case LyXTabular::SET_LTHEAD:
1497 tabular->SetLTHead(actcell,false);
1499 case LyXTabular::SET_LTFOOT:
1500 tabular->SetLTFoot(actcell,false);
1502 case LyXTabular::SET_LTLASTFOOT:
1503 tabular->SetLTFoot(actcell,true);
1505 case LyXTabular::SET_LTNEWPAGE:
1506 what = !tabular->GetLTNewPage(actcell);
1507 tabular->SetLTNewPage(actcell,what);
1513 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1516 // the cursor.pos has to be before the inset so if it isn't now just
1517 // reset the curor pos first!
1518 if (!cellstart(cursor.pos())) {
1519 cursor.pos((cursor.pos() - 1) % 2);
1522 UpdatableInset * inset =
1523 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1524 LyXFont font(LyXFont::ALL_SANE);
1526 x = inset->x() + inset->width(bv, font);
1527 y = inset->descent(bv, font);
1529 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1530 inset_y = cursor.y();
1531 inset->Edit(bv, x - inset_x, y - inset_y, button);
1532 if (!the_locking_inset)
1534 UpdateLocal(bv, CELL, false);
1539 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1541 InsetText * inset = tabular->GetCellInset(actcell);
1544 if (!cellstart(cursor.pos())) {
1545 return (((x + top_x) < cursor.x()) &&
1546 ((x + top_x) > (cursor.x() - inset->width(bv,
1547 LyXFont(LyXFont::ALL_SANE)))));
1549 int x2 = cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1550 return ((x1 > x2) &&
1551 (x1 < (x2 + inset->width(bv, LyXFont(LyXFont::ALL_SANE)))));
1556 // This returns paperWidth() if the cell-width is unlimited or the width
1557 // in pixels if we have a pwidth for this cell.
1558 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1560 string s = tabular->GetPWidth(cell);
1564 return VSpace(s).inPixels( 0, 0);
1568 int InsetTabular::getMaxWidth(Painter & pain,
1569 UpdatableInset const * inset) const
1572 int n = tabular->GetNumberOfCells();
1573 for(cell=0; cell < n; ++cell) {
1574 if (tabular->GetCellInset(cell) == inset)
1579 int w = GetMaxWidthOfCell(pain, cell);
1581 // because the inset then subtracts it's top_x and owner->x()
1582 w += (inset->x() - top_x);
1587 void InsetTabular::resizeLyXText(BufferView *) const
1592 LyXText * InsetTabular::getLyXText(BufferView * bv) const
1594 if (the_locking_inset)
1595 return the_locking_inset->getLyXText(bv);
1596 return Inset::getLyXText(bv);
1600 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1602 if (the_locking_inset) {
1603 InsetTabular * i = static_cast<InsetTabular *>
1604 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1606 i->OpenLayoutDialog(bv);
1610 dialogs_ = bv->owner()->getDialogs();
1611 dialogs_->showTabular(const_cast<InsetTabular *>(this));
1615 // functions returns:
1619 // 3 ... toggled off
1621 LyXFunc::func_status InsetTabular::getStatus(string what) const
1623 int action = LyXTabular::LAST_ACTION;
1626 LyXFunc::func_status status = LyXFunc::OK;
1628 for(i=0; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1629 if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1630 tabularFeatures[i].feature.length())) {
1631 action = tabularFeatures[i].action;
1635 if (action == LyXTabular::LAST_ACTION)
1636 return LyXFunc::Unknown;
1638 argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1640 int sel_row_start, sel_row_end;
1644 if (hasSelection()) {
1646 sel_row_start = tabular->row_of_cell(sel_cell_start);
1647 sel_row_end = tabular->row_of_cell(sel_cell_end);
1648 if (sel_row_start > sel_row_end) {
1649 tmp = sel_row_start;
1650 sel_row_start = sel_row_end;
1654 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1658 case LyXTabular::SET_PWIDTH:
1659 case LyXTabular::SET_MPWIDTH:
1660 case LyXTabular::SET_SPECIAL_COLUMN:
1661 case LyXTabular::SET_SPECIAL_MULTI:
1662 status |= LyXFunc::Disabled;
1665 case LyXTabular::APPEND_ROW:
1666 case LyXTabular::APPEND_COLUMN:
1667 case LyXTabular::DELETE_ROW:
1668 case LyXTabular::DELETE_COLUMN:
1669 case LyXTabular::SET_ALL_LINES:
1670 case LyXTabular::UNSET_ALL_LINES:
1671 status |= LyXFunc::OK;
1674 case LyXTabular::MULTICOLUMN:
1675 if (tabular->IsMultiColumn(actcell))
1676 status |= LyXFunc::ToggleOn;
1678 status |= LyXFunc::ToggleOff;
1680 case LyXTabular::M_TOGGLE_LINE_TOP:
1682 case LyXTabular::TOGGLE_LINE_TOP:
1683 if (tabular->TopLine(actcell, flag))
1684 status |= LyXFunc::ToggleOn;
1686 status |= LyXFunc::ToggleOff;
1688 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1690 case LyXTabular::TOGGLE_LINE_BOTTOM:
1691 if (tabular->BottomLine(actcell, flag))
1692 status |= LyXFunc::ToggleOn;
1694 status |= LyXFunc::ToggleOff;
1696 case LyXTabular::M_TOGGLE_LINE_LEFT:
1698 case LyXTabular::TOGGLE_LINE_LEFT:
1699 if (tabular->LeftLine(actcell, flag))
1700 status |= LyXFunc::ToggleOn;
1702 status |= LyXFunc::ToggleOff;
1704 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1706 case LyXTabular::TOGGLE_LINE_RIGHT:
1707 if (tabular->RightLine(actcell, flag))
1708 status |= LyXFunc::ToggleOn;
1710 status |= LyXFunc::ToggleOff;
1712 case LyXTabular::M_ALIGN_LEFT:
1714 case LyXTabular::ALIGN_LEFT:
1715 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1716 status |= LyXFunc::ToggleOn;
1718 status |= LyXFunc::ToggleOff;
1720 case LyXTabular::M_ALIGN_RIGHT:
1722 case LyXTabular::ALIGN_RIGHT:
1723 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1724 status |= LyXFunc::ToggleOn;
1726 status |= LyXFunc::ToggleOff;
1728 case LyXTabular::M_ALIGN_CENTER:
1730 case LyXTabular::ALIGN_CENTER:
1731 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1732 status |= LyXFunc::ToggleOn;
1734 status |= LyXFunc::ToggleOff;
1736 case LyXTabular::M_VALIGN_TOP:
1738 case LyXTabular::VALIGN_TOP:
1739 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1740 status |= LyXFunc::ToggleOn;
1742 status |= LyXFunc::ToggleOff;
1744 case LyXTabular::M_VALIGN_BOTTOM:
1746 case LyXTabular::VALIGN_BOTTOM:
1747 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1748 status |= LyXFunc::ToggleOn;
1750 status |= LyXFunc::ToggleOff;
1752 case LyXTabular::M_VALIGN_CENTER:
1754 case LyXTabular::VALIGN_CENTER:
1755 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1756 status |= LyXFunc::ToggleOn;
1758 status |= LyXFunc::ToggleOff;
1760 case LyXTabular::SET_LONGTABULAR:
1761 if (tabular->IsLongTabular())
1762 status |= LyXFunc::ToggleOn;
1764 status |= LyXFunc::ToggleOff;
1766 case LyXTabular::UNSET_LONGTABULAR:
1767 if (!tabular->IsLongTabular())
1768 status |= LyXFunc::ToggleOn;
1770 status |= LyXFunc::ToggleOff;
1772 case LyXTabular::SET_ROTATE_TABULAR:
1773 if (tabular->GetRotateTabular())
1774 status |= LyXFunc::ToggleOn;
1776 status |= LyXFunc::ToggleOff;
1778 case LyXTabular::UNSET_ROTATE_TABULAR:
1779 if (!tabular->GetRotateTabular())
1780 status |= LyXFunc::ToggleOn;
1782 status |= LyXFunc::ToggleOff;
1784 case LyXTabular::SET_ROTATE_CELL:
1785 if (tabular->GetRotateCell(actcell))
1786 status |= LyXFunc::ToggleOn;
1788 status |= LyXFunc::ToggleOff;
1790 case LyXTabular::UNSET_ROTATE_CELL:
1791 if (!tabular->GetRotateCell(actcell))
1792 status |= LyXFunc::ToggleOn;
1794 status |= LyXFunc::ToggleOff;
1796 case LyXTabular::SET_USEBOX:
1797 if (strToInt(argument) == tabular->GetUsebox(actcell))
1798 status |= LyXFunc::ToggleOn;
1800 status |= LyXFunc::ToggleOff;
1802 case LyXTabular::SET_LTFIRSTHEAD:
1803 if (tabular->GetRowOfLTHead(actcell, dummy))
1804 status |= LyXFunc::ToggleOn;
1806 status |= LyXFunc::ToggleOff;
1808 case LyXTabular::SET_LTHEAD:
1809 if (tabular->GetRowOfLTHead(actcell, dummy))
1810 status |= LyXFunc::ToggleOn;
1812 status |= LyXFunc::ToggleOff;
1814 case LyXTabular::SET_LTFOOT:
1815 if (tabular->GetRowOfLTFoot(actcell, dummy))
1816 status |= LyXFunc::ToggleOn;
1818 status |= LyXFunc::ToggleOff;
1820 case LyXTabular::SET_LTLASTFOOT:
1821 if (tabular->GetRowOfLTFoot(actcell, dummy))
1822 status |= LyXFunc::ToggleOn;
1824 status |= LyXFunc::ToggleOff;
1826 case LyXTabular::SET_LTNEWPAGE:
1827 if (tabular->GetLTNewPage(actcell))
1828 status |= LyXFunc::ToggleOn;
1830 status |= LyXFunc::ToggleOff;
1833 status = LyXFunc::Disabled;
1840 bool InsetTabular::copySelection()
1842 if (!hasSelection())
1844 delete paste_tabular;
1846 int sel_col_start, sel_col_end;
1847 int sel_row_start, sel_row_end;
1849 sel_col_start = tabular->column_of_cell(sel_cell_start);
1850 sel_col_end = tabular->column_of_cell(sel_cell_end);
1851 if (sel_col_start > sel_col_end) {
1852 sel_col_start = sel_col_end;
1853 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1855 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1857 int columns = sel_col_end - sel_col_start + 1;
1859 sel_row_start = tabular->row_of_cell(sel_cell_start);
1860 sel_row_end = tabular->row_of_cell(sel_cell_end);
1861 if (sel_row_start > sel_row_end) {
1863 tmp = sel_row_start;
1864 sel_row_start = sel_row_end;
1867 int rows = sel_row_end - sel_row_start + 1;
1869 paste_tabular = new LyXTabular(this, rows, columns);
1871 if (sel_cell_start > sel_cell_end) {
1872 int tmp = sel_cell_start;
1873 sel_cell_start = sel_cell_end;
1876 for(int i=sel_cell_start, j=0; i <= sel_cell_end; ++i, ++j) {
1877 while(paste_tabular->row_of_cell(j) <
1878 (tabular->row_of_cell(i)-sel_row_start)) {
1881 while(paste_tabular->row_of_cell(j) >
1882 (tabular->row_of_cell(i)-sel_row_start)) {
1885 *(paste_tabular->GetCellInset(j)) = *(tabular->GetCellInset(i));
1891 bool InsetTabular::pasteSelection(BufferView * bv)
1895 for(int j=0, i=actcell; j<paste_tabular->GetNumberOfCells(); ++j,++i) {
1896 while (paste_tabular->row_of_cell(j) > tabular->row_of_cell(i)-actrow)
1898 if (tabular->GetNumberOfCells() <= i)
1900 while (paste_tabular->row_of_cell(j) < tabular->row_of_cell(i)-actrow)
1902 if (paste_tabular->GetNumberOfCells() <= j)
1904 *(tabular->GetCellInset(i)) = *(paste_tabular->GetCellInset(j));
1905 tabular->GetCellInset(i)->setOwner(this);
1906 tabular->GetCellInset(i)->deleteLyXText(bv);
1912 bool InsetTabular::cutSelection()
1914 if (!hasSelection())
1916 for(int i=sel_cell_start; i < sel_cell_end; ++i) {
1917 tabular->GetCellInset(i)->clear();