1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * ======================================================
19 #pragma implementation
22 #include "insettabular.h"
25 #include "commandtags.h"
27 #include "LaTeXFeatures.h"
31 #include "lyx_gui_misc.h"
34 #include "insets/insettext.h"
35 #include "frontends/Dialogs.h"
39 const int ADD_TO_HEIGHT = 2;
40 const int ADD_TO_TABULAR_WIDTH = 2;
42 static LyXTabular * paste_tabular = 0;
43 bool InsetTabular::hasPasteBuffer() const
45 return (paste_tabular != 0);
55 struct tabular_features {
56 LyXTabular::Feature action;
60 //static tabular_features * tabularFeatures = 0;
62 static tabular_features tabularFeatures[] =
64 { LyXTabular::APPEND_ROW, "append-row" },
65 { LyXTabular::APPEND_COLUMN, "append-column" },
66 { LyXTabular::DELETE_ROW, "delete-row" },
67 { LyXTabular::DELETE_COLUMN, "delete-column" },
68 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
69 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
70 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
71 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
72 { LyXTabular::ALIGN_LEFT, "align-left" },
73 { LyXTabular::ALIGN_RIGHT, "align-right" },
74 { LyXTabular::ALIGN_CENTER, "align-center" },
75 { LyXTabular::VALIGN_TOP, "valign-top" },
76 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
77 { LyXTabular::VALIGN_CENTER, "valign-center" },
78 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
79 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
80 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
81 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
82 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
83 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
84 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
85 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
86 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
87 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
88 { LyXTabular::MULTICOLUMN, "multicolumn" },
89 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
90 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
91 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
92 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
93 { LyXTabular::SET_PWIDTH, "set-pwidth" },
94 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
95 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
96 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
97 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
98 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
99 { LyXTabular::SET_USEBOX, "set-usebox" },
100 { LyXTabular::SET_LTHEAD, "set-lthead" },
101 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
102 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
103 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
104 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
105 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
106 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
107 { LyXTabular::LAST_ACTION, "" }
112 bool cellstart(LyXParagraph::size_type p)
114 return ((p % 2) == 0);
118 InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
125 tabular = new LyXTabular(this, rows,columns);
126 // for now make it always display as display() inset
128 the_locking_inset = 0;
129 locked = no_selection = cursor_visible = false;
134 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
140 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
143 tabular = new LyXTabular(this, *(tab.tabular));
144 the_locking_inset = 0;
145 locked = no_selection = cursor_visible = false;
150 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
156 InsetTabular::~InsetTabular()
160 dialogs_->hideTabular(this);
164 Inset * InsetTabular::Clone() const
166 InsetTabular * t = new InsetTabular(*this, buffer);
168 t->tabular = tabular->Clone(t);
173 void InsetTabular::Write(Buffer const * buf, ostream & os) const
175 os << " Tabular" << endl;
176 tabular->Write(buf, os);
180 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
182 bool old_format = (lex.GetString() == "\\LyXTable");
187 tabular = new LyXTabular(buf, this, lex);
195 token = lex.GetString();
196 while (lex.IsOK() && (token != "\\end_inset")) {
198 token = lex.GetString();
200 if (token != "\\end_inset") {
201 lex.printError("Missing \\end_inset at this point. "
207 int InsetTabular::ascent(BufferView *, LyXFont const &) const
209 return tabular->GetAscentOfRow(0);
213 int InsetTabular::descent(BufferView *, LyXFont const &) const
215 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
219 int InsetTabular::width(BufferView *, LyXFont const &) const
221 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
225 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
226 float & x, bool cleared) const
228 Painter & pain = bv->painter();
233 UpdatableInset::draw(bv, font, baseline, x, cleared);
234 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
235 (top_x != int(x)) || (top_baseline != baseline))) {
236 int h = ascent(bv, font) + descent(bv, font);
237 int tx = display() || !owner() ? 0 : top_x;
238 int w = tx ? width(bv, font) : pain.paperWidth();
239 int ty = baseline - ascent(bv, font);
243 if ((ty + h) > pain.paperHeight())
244 h = pain.paperHeight();
245 if ((top_x + w) > pain.paperWidth())
246 w = pain.paperWidth();
247 pain.fillRectangle(tx, ty, w, h);
252 top_baseline = baseline;
253 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
256 x += ADD_TO_TABULAR_WIDTH;
258 for(i = 0; i < tabular->rows(); ++i) {
260 dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
261 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight();
262 for(j = 0; j < tabular->columns(); ++j) {
263 if (tabular->IsPartOfMultiColumn(i, j))
265 cx = nx + tabular->GetBeginningOfTextInCell(cell);
268 DrawCellSelection(pain, nx, baseline, i, j, cell);
269 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
271 DrawCellLines(pain, nx, baseline, i, cell);
273 nx += tabular->GetWidthOfColumn(cell);
276 baseline += tabular->GetDescentOfRow(i) +
277 tabular->GetAscentOfRow(i + 1) +
278 tabular->GetAdditionalHeight(cell);
280 } else if (need_update == CELL) {
282 for(i = 0; (cell < actcell) && (i < tabular->rows()); ++i) {
284 for(j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
285 if (tabular->IsPartOfMultiColumn(i, j))
287 nx += tabular->GetWidthOfColumn(cell);
290 baseline += tabular->GetDescentOfRow(i) +
291 tabular->GetAscentOfRow(i + 1) +
292 tabular->GetAdditionalHeight(cell);
294 if (the_locking_inset == tabular->GetCellInset(cell)) {
295 cx = nx + tabular->GetBeginningOfTextInCell(cell);
296 LyXText::text_status st = bv->text->status;
298 bv->text->status = st;
299 if (need_update == CELL) {
300 // clear before the inset
303 baseline - tabular->GetAscentOfRow(i) + 1,
305 tabular->GetAscentOfRow(i) +
306 tabular->GetDescentOfRow(i) - 1);
307 // clear behind the inset
309 int(cx + the_locking_inset->width(bv,font) + 1),
310 baseline - tabular->GetAscentOfRow(i) + 1,
311 tabular->GetWidthOfColumn(cell) -
312 tabular->GetBeginningOfTextInCell(cell) -
313 the_locking_inset->width(bv,font) - 1,
314 tabular->GetAscentOfRow(i) +
315 tabular->GetDescentOfRow(i) - 1);
317 tabular->GetCellInset(cell)->draw(bv,font,baseline, cx, false);
318 } while(bv->text->status == LyXText::CHANGED_IN_DRAW);
321 x -= ADD_TO_TABULAR_WIDTH;
322 x += width(bv, font);
323 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
330 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
331 int row, int cell) const
333 int x2 = x + tabular->GetWidthOfColumn(cell);
336 if (!tabular->TopAlreadyDrawed(cell)) {
337 on_off = !tabular->TopLine(cell);
338 pain.line(x, baseline - tabular->GetAscentOfRow(row),
339 x2, baseline - tabular->GetAscentOfRow(row),
340 on_off ? LColor::tabularonoffline : LColor::tabularline,
341 on_off ? Painter::line_onoffdash : Painter::line_solid);
343 on_off = !tabular->BottomLine(cell);
344 pain.line(x,baseline + tabular->GetDescentOfRow(row),
345 x2, baseline + tabular->GetDescentOfRow(row),
346 on_off ? LColor::tabularonoffline : LColor::tabularline,
347 on_off ? Painter::line_onoffdash : Painter::line_solid);
348 if (!tabular->LeftAlreadyDrawed(cell)) {
349 on_off = !tabular->LeftLine(cell);
350 pain.line(x, baseline - tabular->GetAscentOfRow(row),
351 x, baseline + tabular->GetDescentOfRow(row),
352 on_off ? LColor::tabularonoffline : LColor::tabularline,
353 on_off ? Painter::line_onoffdash : Painter::line_solid);
355 on_off = !tabular->RightLine(cell);
356 pain.line(x2 - tabular->GetAdditionalWidth(cell),
357 baseline - tabular->GetAscentOfRow(row),
358 x2 - tabular->GetAdditionalWidth(cell),
359 baseline + tabular->GetDescentOfRow(row),
360 on_off ? LColor::tabularonoffline : LColor::tabularline,
361 on_off ? Painter::line_onoffdash : Painter::line_solid);
365 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
366 int row, int column, int cell) const
368 int cs = tabular->column_of_cell(sel_cell_start);
369 int ce = tabular->column_of_cell(sel_cell_end);
372 cs = tabular->column_of_cell(sel_cell_end);
374 ce = tabular->right_column_of_cell(sel_cell_end);
377 int rs = tabular->row_of_cell(sel_cell_start);
378 int re = tabular->row_of_cell(sel_cell_end);
379 if (rs > re) swap(rs, re);
381 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
382 int w = tabular->GetWidthOfColumn(cell);
383 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
384 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
385 w, h, LColor::selection);
390 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
394 calculate_dimensions_of_cells(bv, font, true);
396 owner()->update(bv, font, true);
399 if (the_locking_inset) {
400 the_locking_inset->update(bv, font, reinit);
402 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
403 inset_y = cursor.y();
405 switch(need_update) {
409 if (calculate_dimensions_of_cells(bv, font, false))
421 string const InsetTabular::EditMessage() const
423 return _("Opened Tabular Inset");
427 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
429 UpdatableInset::Edit(bv, x, y, button);
431 if (!bv->lockInset(this)) {
432 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
436 the_locking_inset = 0;
437 inset_pos = inset_x = inset_y = 0;
439 sel_pos_start = sel_pos_end = cursor.pos();
440 sel_cell_start = sel_cell_end = actcell;
441 bv->text->FinishUndo();
442 if (InsetHit(bv, x, y)) {
443 ActivateCellInset(bv, x, y, button);
445 UpdateLocal(bv, NONE, false);
446 // bv->getOwner()->getPopups().updateFormTabular();
450 void InsetTabular::InsetUnlock(BufferView * bv)
452 if (the_locking_inset) {
453 the_locking_inset->InsetUnlock(bv);
454 the_locking_inset = 0;
457 no_selection = false;
460 if (scroll() || hasSelection()) {
464 sel_pos_start = sel_pos_end = 0;
465 sel_cell_start = sel_cell_end = 0;
467 UpdateLocal(bv, FULL, false);
472 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
473 bool mark_dirty) const
477 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
478 if (locked && (what != NONE))
483 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
485 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
489 if (inset == tabular->GetCellInset(actcell)) {
490 lyxerr[Debug::INSETS] << "OK" << endl;
491 the_locking_inset = tabular->GetCellInset(actcell);
493 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
494 inset_y = cursor.y();
495 inset_pos = cursor.pos();
497 } else if (the_locking_inset && (the_locking_inset == inset)) {
498 if (cursor.pos() == inset_pos) {
499 lyxerr[Debug::INSETS] << "OK" << endl;
501 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
502 inset_y = cursor.y();
504 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
506 } else if (the_locking_inset) {
507 lyxerr[Debug::INSETS] << "MAYBE" << endl;
508 return the_locking_inset->LockInsetInInset(bv, inset);
510 lyxerr[Debug::INSETS] << "NOT OK" << endl;
515 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
518 if (!the_locking_inset)
520 if (the_locking_inset == inset) {
521 the_locking_inset->InsetUnlock(bv);
522 the_locking_inset = 0;
524 moveRight(bv, false);
525 UpdateLocal(bv, CELL, false);
528 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
529 if (inset->LyxCode() == TABULAR_CODE &&
530 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
532 dialogs_ = bv->owner()->getDialogs();
533 dialogs_->updateTabular(this);
542 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
544 if (!the_locking_inset)
546 if (the_locking_inset != inset)
547 return the_locking_inset->UpdateInsetInInset(bv, inset);
548 UpdateLocal(bv, CELL, false);
553 int InsetTabular::InsetInInsetY()
555 if (!the_locking_inset)
558 return (inset_y + the_locking_inset->InsetInInsetY());
562 UpdatableInset * InsetTabular::GetLockingInset()
564 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
568 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
572 if (the_locking_inset)
573 return the_locking_inset->GetFirstLockingInsetOfType(c);
578 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
580 if (the_locking_inset)
581 return the_locking_inset->InsertInset(bv, inset);
586 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
588 if (hasSelection()) {
589 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
590 UpdateLocal(bv, SELECTION, false);
592 no_selection = false;
594 int const ocell = actcell;
595 int const orow = actrow;
600 UpdateLocal(bv, NONE, false);
601 sel_pos_start = sel_pos_end = cursor.pos();
602 sel_cell_start = sel_cell_end = actcell;
604 bool const inset_hit = InsetHit(bv, x, y);
606 if ((ocell == actcell) && the_locking_inset && inset_hit) {
607 the_locking_inset->InsetButtonPress(bv,
608 x - inset_x, y - inset_y, button);
610 } else if (the_locking_inset) {
611 the_locking_inset->InsetUnlock(bv);
613 the_locking_inset = 0;
614 if (inset_hit && bv->the_locking_inset) {
615 if (ActivateCellInset(bv, x, y, button))
616 the_locking_inset->InsetButtonPress(bv, x - inset_x,
617 y - inset_y, button);
624 void InsetTabular::InsetButtonRelease(BufferView * bv,
625 int x, int y, int button)
628 if (the_locking_inset) {
630 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
631 i->InsetButtonRelease(bv, x, y, button);
635 dialogs_ = bv->owner()->getDialogs();
636 dialogs_->showTabular(this);
639 if (the_locking_inset) {
640 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
643 no_selection = false;
647 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
649 if (the_locking_inset) {
650 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
651 y - inset_y, button);
656 int const old_pos = sel_pos_end;
657 int const old_cell = actcell;
660 sel_pos_end = cursor.pos();
661 sel_cell_end = actcell;
662 if ((sel_cell_end != old_cell) || (old_pos != sel_pos_end))
663 UpdateLocal(bv, SELECTION, false);
666 no_selection = false;
670 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
672 if (the_locking_inset) {
673 the_locking_inset->InsetKeyPress(xke);
679 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
682 UpdatableInset::RESULT
685 no_selection = false;
686 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
687 || (result == DISPATCHED_NOUPDATE)) {
693 if ((action < 0) && arg.empty())
696 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
697 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
699 if (the_locking_inset) {
700 result=the_locking_inset->LocalDispatch(bv, action, arg);
701 if (result == DISPATCHED_NOUPDATE)
703 else if (result == DISPATCHED) {
704 the_locking_inset->ToggleInsetCursor(bv);
705 UpdateLocal(bv, CELL, false);
706 the_locking_inset->ToggleInsetCursor(bv);
708 } else if (result == FINISHED) {
709 if ((action == LFUN_RIGHT) || (action == -1)) {
710 cursor.pos(inset_pos + 1);
713 sel_pos_start = sel_pos_end = cursor.pos();
714 sel_cell_start = sel_cell_end = actcell;
721 bool hs = hasSelection();
725 // Normal chars not handled here
728 // --- Cursor Movements ---------------------------------------------
730 if (tabular->IsLastCellInRow(actcell) && !cellstart(cursor.pos()))
732 moveRight(bv, false);
733 sel_pos_end = cursor.pos();
734 if (!cellstart(cursor.pos())) {
735 if (tabular->right_column_of_cell(sel_cell_start) >
736 tabular->right_column_of_cell(actcell))
737 sel_cell_end = actcell+1;
739 sel_cell_end = actcell;
741 UpdateLocal(bv, SELECTION, false);
744 result = moveRight(bv);
745 sel_pos_start = sel_pos_end = cursor.pos();
746 sel_cell_start = sel_cell_end = actcell;
748 UpdateLocal(bv, SELECTION, false);
751 if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos()))
754 sel_pos_end = cursor.pos();
755 if (cellstart(cursor.pos())) {
756 if (tabular->column_of_cell(sel_cell_start) >=
757 tabular->column_of_cell(actcell))
758 sel_cell_end = actcell;
760 sel_cell_end = actcell-1;
762 UpdateLocal(bv, SELECTION, false);
765 result = moveLeft(bv);
766 sel_pos_start = sel_pos_end = cursor.pos();
767 sel_cell_start = sel_cell_end = actcell;
769 UpdateLocal(bv, SELECTION, false);
773 int const ocell = actcell;
775 sel_pos_end = cursor.pos();
776 if ((ocell == sel_cell_end) ||
777 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
778 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
780 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
781 UpdateLocal(bv, SELECTION, false);
785 result = moveDown(bv);
786 sel_pos_start = sel_pos_end = cursor.pos();
787 sel_cell_start = sel_cell_end = actcell;
789 UpdateLocal(bv, SELECTION, false);
793 int const ocell = actcell;
795 sel_pos_end = cursor.pos();
796 if ((ocell == sel_cell_end) ||
797 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
798 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
800 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
801 UpdateLocal(bv, SELECTION, false);
806 sel_pos_start = sel_pos_end = cursor.pos();
807 sel_cell_start = sel_cell_end = actcell;
809 UpdateLocal(bv, SELECTION, false);
821 if (the_locking_inset) {
822 UnlockInsetInInset(bv, the_locking_inset);
823 the_locking_inset = 0;
825 if (action == LFUN_TAB)
829 sel_pos_start = sel_pos_end = cursor.pos();
830 sel_cell_start = sel_cell_end = actcell;
832 UpdateLocal(bv, SELECTION, false);
834 case LFUN_LAYOUT_TABULAR:
836 dialogs_ = bv->owner()->getDialogs();
837 dialogs_->showTabular(this);
840 case LFUN_TABULAR_FEATURE:
841 if (!TabularFeatures(bv, arg))
842 result = UNDISPATCHED;
845 if (!copySelection())
847 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
849 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
850 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
852 bv->text->cursor.par()->previous,
853 bv->text->cursor.par()->next
857 UpdateLocal(bv, INIT, true);
862 bv->text->FinishUndo();
866 if (!hasPasteBuffer())
868 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
870 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
871 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
873 bv->text->cursor.par()->previous,
874 bv->text->cursor.par()->next
878 UpdateLocal(bv, INIT, true);
881 result = UNDISPATCHED;
884 if (result!=FINISHED) {
885 if (!the_locking_inset) {
887 if (ocell != actcell)
888 bview->getOwner()->getPopups().updateFormTabular();
893 bv->unlockInset(this);
898 int InsetTabular::Latex(Buffer const * buf, ostream & os,
899 bool fragile, bool fp) const
901 return tabular->Latex(buf, os, fragile, fp);
905 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
907 // This should be changed to a real ascii export
908 return tabular->Latex(buf, os, false, false);
912 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
918 int InsetTabular::DocBook(Buffer const *, ostream &) const
924 void InsetTabular::Validate(LaTeXFeatures & features) const
926 tabular->Validate(features);
930 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
931 LyXFont const & font,
937 bool changed = false;
939 for(int i = 0; i < tabular->rows(); ++i) {
940 maxAsc = maxDesc = 0;
941 for(int j= 0; j < tabular->columns(); ++j) {
942 if (tabular->IsPartOfMultiColumn(i,j))
945 inset = tabular->GetCellInset(cell);
947 inset->update(bv, font, false);
948 maxAsc = max(maxAsc, inset->ascent(bv, font));
949 maxDesc = max(maxDesc, inset->descent(bv, font));
950 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
952 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
953 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
959 void InsetTabular::GetCursorPos(BufferView *,
960 unsigned long & x, unsigned long & y) const
962 x = cursor.x() - top_x;
967 void InsetTabular::ToggleInsetCursor(BufferView * bv)
969 if (the_locking_inset) {
970 the_locking_inset->ToggleInsetCursor(bv);
974 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
976 int const asc = lyxfont::maxAscent(font);
977 int const desc = lyxfont::maxDescent(font);
980 bv->hideLockedInsetCursor();
982 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
983 cursor_visible = !cursor_visible;
987 void InsetTabular::ShowInsetCursor(BufferView * bv)
989 if (!cursor_visible) {
990 LyXFont font; // = GetFont(par, cursor.pos);
992 int const asc = lyxfont::maxAscent(font);
993 int const desc = lyxfont::maxDescent(font);
994 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
995 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
996 cursor_visible = true;
1001 void InsetTabular::HideInsetCursor(BufferView * bv)
1003 if (cursor_visible) {
1004 bv->hideLockedInsetCursor();
1005 cursor_visible = false;
1007 // if (cursor_visible)
1008 // ToggleInsetCursor(bv);
1012 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1017 actcell = actrow = actcol = 0;
1018 int ly = tabular->GetDescentOfRow(actrow);
1020 // first search the right row
1021 while((ly < y) && (actrow < tabular->rows())) {
1022 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1023 tabular->GetAscentOfRow(actrow+1) +
1024 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1027 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1029 actcell = tabular->GetCellNumber(actrow, actcol);
1031 // now search the right column
1032 int lx = tabular->GetWidthOfColumn(actcell) -
1033 tabular->GetAdditionalWidth(actcell);
1034 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
1035 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1036 tabular->GetAdditionalWidth(actcell - 1));
1039 if ((lx - (tabular->GetWidthOfColumn(actcell) / 2)) < x) {
1040 cursor.x(lx + top_x - 2);
1043 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1049 int InsetTabular::getCellXPos(int cell) const
1053 for(; !tabular->IsFirstCellInRow(c); --c)
1055 int lx = tabular->GetWidthOfColumn(cell);
1056 for(; (c < cell); ++c) {
1057 lx += tabular->GetWidthOfColumn(c);
1059 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1063 void InsetTabular::resetPos(BufferView * bv) const
1067 actcol = tabular->column_of_cell(actcell);
1072 for(; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1073 if (tabular->IsLastCellInRow(cell)) {
1074 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1075 tabular->GetAscentOfRow(actrow + 1) +
1076 tabular->GetAdditionalHeight(cell + 1));
1080 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1081 cursor.x(getCellXPos(actcell) + offset);
1082 if (((cursor.x() - offset) > 20) &&
1083 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1084 (bv->workWidth()-20)))
1086 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1087 UpdateLocal(bv, FULL, false);
1088 } else if ((cursor.x() - offset) < 20) {
1089 scroll(bv, 20 - cursor.x() + offset);
1090 UpdateLocal(bv, FULL, false);
1091 } else if (!cellstart(cursor.pos())) {
1092 LyXFont font(LyXFont::ALL_SANE);
1093 cursor.x(cursor.x() + tabular->GetCellInset(actcell)->width(bv,font) +
1094 tabular->GetBeginningOfTextInCell(actcell));
1096 if ((!the_locking_inset ||
1097 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1098 (actcell != oldcell)) {
1099 dialogs_ = bv->owner()->getDialogs();
1100 dialogs_->updateTabular(const_cast<InsetTabular *>(this));
1106 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1108 if (!cellstart(cursor.pos())) {
1109 if (tabular->IsLastCell(actcell))
1112 cursor.pos((cursor.pos() + 1) % 2);
1114 if (ActivateCellInset(bv))
1116 } else { // before the inset
1117 cursor.pos((cursor.pos() + 1) % 2);
1120 return DISPATCHED_NOUPDATE;
1124 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1126 if (!cursor.pos()) {
1131 cursor.pos((cursor.pos() - 1) % 2);
1132 if (!cellstart(cursor.pos())) {
1134 } else if (lock) { // behind the inset
1135 if (ActivateCellInset(bv, 0, 0, 0, true))
1139 return DISPATCHED_NOUPDATE;
1143 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv)
1145 int const ocell = actcell;
1146 actcell = tabular->GetCellAbove(actcell);
1147 if (actcell == ocell) // we moved out of the inset
1150 return DISPATCHED_NOUPDATE;
1154 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv)
1156 int const ocell = actcell;
1157 actcell = tabular->GetCellBelow(actcell);
1158 if (actcell == ocell) // we moved out of the inset
1161 return DISPATCHED_NOUPDATE;
1165 bool InsetTabular::moveNextCell(BufferView * bv)
1167 if (tabular->IsLastCell(actcell))
1170 cursor.pos((cursor.pos() + 1) % 2);
1171 if (!cellstart(cursor.pos()))
1172 cursor.pos((cursor.pos() + 1) % 2);
1178 bool InsetTabular::movePrevCell(BufferView * bv)
1180 if (!actcell) // first cell
1183 cursor.pos((cursor.pos() - 1) % 2);
1184 if (cellstart(cursor.pos()))
1185 cursor.pos((cursor.pos() - 1) % 2);
1191 bool InsetTabular::Delete()
1197 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1199 if (the_locking_inset)
1200 the_locking_inset->SetFont(bv, font, tall);
1204 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1206 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1209 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1210 string const tmp = tabularFeatures[i].feature;
1212 if (tmp == what.substr(0, tmp.length())) {
1213 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1214 //tabularFeatures[i].feature.length())) {
1215 action = tabularFeatures[i].action;
1219 if (action == LyXTabular::LAST_ACTION)
1223 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1224 TabularFeatures(bv, action, val);
1229 void InsetTabular::TabularFeatures(BufferView * bv,
1230 LyXTabular::Feature feature,
1231 string const & value)
1240 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1241 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1246 case LyXTabular::M_ALIGN_LEFT:
1247 case LyXTabular::ALIGN_LEFT:
1248 setAlign=LYX_ALIGN_LEFT;
1250 case LyXTabular::M_ALIGN_RIGHT:
1251 case LyXTabular::ALIGN_RIGHT:
1252 setAlign=LYX_ALIGN_RIGHT;
1254 case LyXTabular::M_ALIGN_CENTER:
1255 case LyXTabular::ALIGN_CENTER:
1256 setAlign=LYX_ALIGN_CENTER;
1258 case LyXTabular::M_VALIGN_TOP:
1259 case LyXTabular::VALIGN_TOP:
1260 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1262 case LyXTabular::M_VALIGN_BOTTOM:
1263 case LyXTabular::VALIGN_BOTTOM:
1264 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1266 case LyXTabular::M_VALIGN_CENTER:
1267 case LyXTabular::VALIGN_CENTER:
1268 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1273 if (hasSelection()) {
1274 sel_col_start = tabular->column_of_cell(sel_cell_start);
1275 sel_col_end = tabular->column_of_cell(sel_cell_end);
1276 if (sel_col_start > sel_col_end) {
1277 sel_col_end = sel_col_start;
1278 sel_col_start = tabular->column_of_cell(sel_cell_end);
1280 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1283 sel_row_start = tabular->row_of_cell(sel_cell_start);
1284 sel_row_end = tabular->row_of_cell(sel_cell_end);
1285 if (sel_row_start > sel_row_end) {
1286 //int tmp = sel_row_start;
1287 //sel_row_start = sel_row_end;
1288 //sel_row_end = tmp;
1289 swap(sel_row_start, sel_row_end);
1292 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1293 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1295 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1297 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1298 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1300 bv->text->cursor.par()->previous,
1301 bv->text->cursor.par()->next
1305 int row = tabular->row_of_cell(actcell);
1306 int column = tabular->column_of_cell(actcell);
1310 case LyXTabular::SET_PWIDTH:
1312 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1313 tabular->SetColumnPWidth(actcell,value);
1315 for (int i=0; i < tabular->rows(); ++i) {
1316 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1319 UpdateLocal(bv, INIT, true);
1323 case LyXTabular::SET_MPWIDTH:
1325 bool const update = (tabular->GetPWidth(actcell) != value);
1326 tabular->SetMColumnPWidth(actcell,value);
1328 for (int i=0; i < tabular->rows(); ++i) {
1329 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1332 UpdateLocal(bv, INIT, true);
1336 case LyXTabular::SET_SPECIAL_COLUMN:
1337 case LyXTabular::SET_SPECIAL_MULTI:
1338 tabular->SetAlignSpecial(actcell,value,feature);
1340 case LyXTabular::APPEND_ROW:
1341 // append the row into the tabular
1342 UnlockInsetInInset(bv, the_locking_inset);
1343 tabular->AppendRow(actcell);
1344 UpdateLocal(bv, INIT, true);
1346 case LyXTabular::APPEND_COLUMN:
1347 // append the column into the tabular
1348 tabular->AppendColumn(actcell);
1349 actcell = tabular->GetCellNumber(row, column);
1350 UpdateLocal(bv, INIT, true);
1352 case LyXTabular::DELETE_ROW:
1353 tabular->DeleteRow(tabular->row_of_cell(actcell));
1354 if ((row+1) > tabular->rows())
1356 actcell = tabular->GetCellNumber(row, column);
1357 UpdateLocal(bv, INIT, true);
1359 case LyXTabular::DELETE_COLUMN:
1360 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1361 if ((column+1) > tabular->columns())
1363 actcell = tabular->GetCellNumber(row, column);
1364 UpdateLocal(bv, INIT, true);
1366 case LyXTabular::M_TOGGLE_LINE_TOP:
1368 case LyXTabular::TOGGLE_LINE_TOP:
1369 lineSet = !tabular->TopLine(actcell, flag);
1370 for(i=sel_row_start; i<=sel_row_end; ++i)
1371 for(j=sel_col_start; j<=sel_col_end; ++j)
1372 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1373 UpdateLocal(bv, INIT, true);
1376 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1378 case LyXTabular::TOGGLE_LINE_BOTTOM:
1379 lineSet = !tabular->BottomLine(actcell, flag);
1380 for(i=sel_row_start; i<=sel_row_end; ++i)
1381 for(j=sel_col_start; j<=sel_col_end; ++j)
1382 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1384 UpdateLocal(bv, INIT, true);
1387 case LyXTabular::M_TOGGLE_LINE_LEFT:
1389 case LyXTabular::TOGGLE_LINE_LEFT:
1390 lineSet = !tabular->LeftLine(actcell, flag);
1391 for(i=sel_row_start; i<=sel_row_end; ++i)
1392 for(j=sel_col_start; j<=sel_col_end; ++j)
1393 tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1395 UpdateLocal(bv, INIT, true);
1398 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1400 case LyXTabular::TOGGLE_LINE_RIGHT:
1401 lineSet = !tabular->RightLine(actcell, flag);
1402 for(i=sel_row_start; i<=sel_row_end; ++i)
1403 for(j=sel_col_start; j<=sel_col_end; ++j)
1404 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1406 UpdateLocal(bv, INIT, true);
1408 case LyXTabular::M_ALIGN_LEFT:
1409 case LyXTabular::M_ALIGN_RIGHT:
1410 case LyXTabular::M_ALIGN_CENTER:
1412 case LyXTabular::ALIGN_LEFT:
1413 case LyXTabular::ALIGN_RIGHT:
1414 case LyXTabular::ALIGN_CENTER:
1415 for(i = sel_row_start; i <= sel_row_end; ++i)
1416 for(j = sel_col_start; j <= sel_col_end; ++j)
1417 tabular->SetAlignment(tabular->GetCellNumber(i, j), setAlign,
1420 UpdateLocal(bv, INIT, true);
1422 UpdateLocal(bv, CELL, true);
1424 case LyXTabular::M_VALIGN_TOP:
1425 case LyXTabular::M_VALIGN_BOTTOM:
1426 case LyXTabular::M_VALIGN_CENTER:
1428 case LyXTabular::VALIGN_TOP:
1429 case LyXTabular::VALIGN_BOTTOM:
1430 case LyXTabular::VALIGN_CENTER:
1431 for(i = sel_row_start; i <= sel_row_end; ++i)
1432 for(j = sel_col_start; j <= sel_col_end; ++j)
1433 tabular->SetVAlignment(tabular->GetCellNumber(i, j),
1436 UpdateLocal(bv, INIT, true);
1438 UpdateLocal(bv, CELL, true);
1440 case LyXTabular::MULTICOLUMN:
1442 if (sel_row_start != sel_row_end) {
1443 WriteAlert(_("Impossible Operation!"),
1444 _("Multicolumns can only be horizontally."),
1448 // just multicol for one Single Cell
1449 if (!hasSelection()) {
1450 // check wether we are completly in a multicol
1451 if (tabular->IsMultiColumn(actcell)) {
1452 tabular->UnsetMultiColumn(actcell);
1453 UpdateLocal(bv, INIT, true);
1455 tabular->SetMultiColumn(actcell, 1);
1456 UpdateLocal(bv, CELL, true);
1460 // we have a selection so this means we just add all this
1461 // cells to form a multicolumn cell
1465 if (sel_cell_start > sel_cell_end) {
1466 s_start = sel_cell_end;
1467 s_end = sel_cell_start;
1469 s_start = sel_cell_start;
1470 s_end = sel_cell_end;
1472 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1475 sel_cell_end = sel_cell_start;
1476 sel_pos_end = sel_pos_start;
1477 UpdateLocal(bv, INIT, true);
1480 case LyXTabular::SET_ALL_LINES:
1482 case LyXTabular::UNSET_ALL_LINES:
1483 for(i=sel_row_start; i<=sel_row_end; ++i)
1484 for(j=sel_col_start; j<=sel_col_end; ++j)
1485 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1486 UpdateLocal(bv, INIT, true);
1488 case LyXTabular::SET_LONGTABULAR:
1489 tabular->SetLongTabular(true);
1490 UpdateLocal(bv, INIT, true); // because this toggles displayed
1492 case LyXTabular::UNSET_LONGTABULAR:
1493 tabular->SetLongTabular(false);
1494 UpdateLocal(bv, INIT, true); // because this toggles displayed
1496 case LyXTabular::SET_ROTATE_TABULAR:
1497 tabular->SetRotateTabular(true);
1499 case LyXTabular::UNSET_ROTATE_TABULAR:
1500 tabular->SetRotateTabular(false);
1502 case LyXTabular::SET_ROTATE_CELL:
1503 for(i=sel_row_start; i<=sel_row_end; ++i)
1504 for(j=sel_col_start; j<=sel_col_end; ++j)
1505 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1507 case LyXTabular::UNSET_ROTATE_CELL:
1508 for(i = sel_row_start; i <= sel_row_end; ++i)
1509 for(j = sel_col_start; j <= sel_col_end; ++j)
1510 tabular->SetRotateCell(tabular->GetCellNumber(i, j), false);
1512 case LyXTabular::SET_USEBOX:
1514 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1515 if (val == tabular->GetUsebox(actcell))
1516 val = LyXTabular::BOX_NONE;
1517 for(i = sel_row_start; i <= sel_row_end; ++i)
1518 for(j = sel_col_start; j <= sel_col_end; ++j)
1519 tabular->SetUsebox(tabular->GetCellNumber(i, j), val);
1522 case LyXTabular::SET_LTFIRSTHEAD:
1523 tabular->SetLTHead(actcell, true);
1525 case LyXTabular::SET_LTHEAD:
1526 tabular->SetLTHead(actcell, false);
1528 case LyXTabular::SET_LTFOOT:
1529 tabular->SetLTFoot(actcell, false);
1531 case LyXTabular::SET_LTLASTFOOT:
1532 tabular->SetLTFoot(actcell, true);
1534 case LyXTabular::SET_LTNEWPAGE:
1535 what = !tabular->GetLTNewPage(actcell);
1536 tabular->SetLTNewPage(actcell, what);
1538 // dummy stuff just to avoid warnings
1539 case LyXTabular::LAST_ACTION:
1545 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1548 // the cursor.pos has to be before the inset so if it isn't now just
1549 // reset the curor pos first!
1550 if (!cellstart(cursor.pos())) {
1551 cursor.pos((cursor.pos() - 1) % 2);
1554 UpdatableInset * inset =
1555 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1556 LyXFont font(LyXFont::ALL_SANE);
1558 x = inset->x() + inset->width(bv, font);
1559 y = inset->descent(bv, font);
1561 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1562 inset_y = cursor.y();
1563 inset->Edit(bv, x - inset_x, y - inset_y, button);
1564 if (!the_locking_inset)
1566 UpdateLocal(bv, CELL, false);
1567 return (the_locking_inset != 0);
1571 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1573 InsetText * inset = tabular->GetCellInset(actcell);
1576 if (!cellstart(cursor.pos())) {
1577 return (((x + top_x) < cursor.x()) &&
1578 ((x + top_x) > (cursor.x() - inset->width(bv,
1579 LyXFont(LyXFont::ALL_SANE)))));
1581 int x2 = cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1582 return ((x1 > x2) &&
1583 (x1 < (x2 + inset->width(bv, LyXFont(LyXFont::ALL_SANE)))));
1588 // This returns paperWidth() if the cell-width is unlimited or the width
1589 // in pixels if we have a pwidth for this cell.
1590 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1592 string const s = tabular->GetPWidth(cell);
1596 return VSpace(s).inPixels(0, 0);
1600 int InsetTabular::getMaxWidth(Painter & pain,
1601 UpdatableInset const * inset) const
1603 int const n = tabular->GetNumberOfCells();
1605 for(; cell < n; ++cell) {
1606 if (tabular->GetCellInset(cell) == inset)
1611 int w = GetMaxWidthOfCell(pain, cell);
1613 // because the inset then subtracts it's top_x and owner->x()
1614 w += (inset->x() - top_x);
1619 void InsetTabular::resizeLyXText(BufferView *) const
1625 LyXText * InsetTabular::getLyXText(BufferView * bv) const
1627 if (the_locking_inset)
1628 return the_locking_inset->getLyXText(bv);
1629 return Inset::getLyXText(bv);
1633 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1635 if (the_locking_inset) {
1636 InsetTabular * i = static_cast<InsetTabular *>
1637 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1639 i->OpenLayoutDialog(bv);
1643 dialogs_ = bv->owner()->getDialogs();
1644 dialogs_->showTabular(const_cast<InsetTabular *>(this));
1648 // functions returns:
1652 // 3 ... toggled off
1654 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1656 int action = LyXTabular::LAST_ACTION;
1657 LyXFunc::func_status status = LyXFunc::OK;
1660 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1661 string const tmp = tabularFeatures[i].feature;
1662 if (tmp == what.substr(0, tmp.length())) {
1663 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1664 // tabularFeatures[i].feature.length())) {
1665 action = tabularFeatures[i].action;
1669 if (action == LyXTabular::LAST_ACTION)
1670 return LyXFunc::Unknown;
1672 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1674 int sel_row_start, sel_row_end;
1678 if (hasSelection()) {
1679 sel_row_start = tabular->row_of_cell(sel_cell_start);
1680 sel_row_end = tabular->row_of_cell(sel_cell_end);
1681 if (sel_row_start > sel_row_end) {
1682 //int tmp = sel_row_start;
1683 //sel_row_start = sel_row_end;
1684 //sel_row_end = tmp;
1685 swap(sel_row_start, sel_row_end);
1688 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1692 case LyXTabular::SET_PWIDTH:
1693 case LyXTabular::SET_MPWIDTH:
1694 case LyXTabular::SET_SPECIAL_COLUMN:
1695 case LyXTabular::SET_SPECIAL_MULTI:
1696 status |= LyXFunc::Disabled;
1699 case LyXTabular::APPEND_ROW:
1700 case LyXTabular::APPEND_COLUMN:
1701 case LyXTabular::DELETE_ROW:
1702 case LyXTabular::DELETE_COLUMN:
1703 case LyXTabular::SET_ALL_LINES:
1704 case LyXTabular::UNSET_ALL_LINES:
1705 status |= LyXFunc::OK;
1708 case LyXTabular::MULTICOLUMN:
1709 if (tabular->IsMultiColumn(actcell))
1710 status |= LyXFunc::ToggleOn;
1712 status |= LyXFunc::ToggleOff;
1714 case LyXTabular::M_TOGGLE_LINE_TOP:
1716 case LyXTabular::TOGGLE_LINE_TOP:
1717 if (tabular->TopLine(actcell, flag))
1718 status |= LyXFunc::ToggleOn;
1720 status |= LyXFunc::ToggleOff;
1722 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1724 case LyXTabular::TOGGLE_LINE_BOTTOM:
1725 if (tabular->BottomLine(actcell, flag))
1726 status |= LyXFunc::ToggleOn;
1728 status |= LyXFunc::ToggleOff;
1730 case LyXTabular::M_TOGGLE_LINE_LEFT:
1732 case LyXTabular::TOGGLE_LINE_LEFT:
1733 if (tabular->LeftLine(actcell, flag))
1734 status |= LyXFunc::ToggleOn;
1736 status |= LyXFunc::ToggleOff;
1738 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1740 case LyXTabular::TOGGLE_LINE_RIGHT:
1741 if (tabular->RightLine(actcell, flag))
1742 status |= LyXFunc::ToggleOn;
1744 status |= LyXFunc::ToggleOff;
1746 case LyXTabular::M_ALIGN_LEFT:
1748 case LyXTabular::ALIGN_LEFT:
1749 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1750 status |= LyXFunc::ToggleOn;
1752 status |= LyXFunc::ToggleOff;
1754 case LyXTabular::M_ALIGN_RIGHT:
1756 case LyXTabular::ALIGN_RIGHT:
1757 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1758 status |= LyXFunc::ToggleOn;
1760 status |= LyXFunc::ToggleOff;
1762 case LyXTabular::M_ALIGN_CENTER:
1764 case LyXTabular::ALIGN_CENTER:
1765 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1766 status |= LyXFunc::ToggleOn;
1768 status |= LyXFunc::ToggleOff;
1770 case LyXTabular::M_VALIGN_TOP:
1772 case LyXTabular::VALIGN_TOP:
1773 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1774 status |= LyXFunc::ToggleOn;
1776 status |= LyXFunc::ToggleOff;
1778 case LyXTabular::M_VALIGN_BOTTOM:
1780 case LyXTabular::VALIGN_BOTTOM:
1781 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1782 status |= LyXFunc::ToggleOn;
1784 status |= LyXFunc::ToggleOff;
1786 case LyXTabular::M_VALIGN_CENTER:
1788 case LyXTabular::VALIGN_CENTER:
1789 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1790 status |= LyXFunc::ToggleOn;
1792 status |= LyXFunc::ToggleOff;
1794 case LyXTabular::SET_LONGTABULAR:
1795 if (tabular->IsLongTabular())
1796 status |= LyXFunc::ToggleOn;
1798 status |= LyXFunc::ToggleOff;
1800 case LyXTabular::UNSET_LONGTABULAR:
1801 if (!tabular->IsLongTabular())
1802 status |= LyXFunc::ToggleOn;
1804 status |= LyXFunc::ToggleOff;
1806 case LyXTabular::SET_ROTATE_TABULAR:
1807 if (tabular->GetRotateTabular())
1808 status |= LyXFunc::ToggleOn;
1810 status |= LyXFunc::ToggleOff;
1812 case LyXTabular::UNSET_ROTATE_TABULAR:
1813 if (!tabular->GetRotateTabular())
1814 status |= LyXFunc::ToggleOn;
1816 status |= LyXFunc::ToggleOff;
1818 case LyXTabular::SET_ROTATE_CELL:
1819 if (tabular->GetRotateCell(actcell))
1820 status |= LyXFunc::ToggleOn;
1822 status |= LyXFunc::ToggleOff;
1824 case LyXTabular::UNSET_ROTATE_CELL:
1825 if (!tabular->GetRotateCell(actcell))
1826 status |= LyXFunc::ToggleOn;
1828 status |= LyXFunc::ToggleOff;
1830 case LyXTabular::SET_USEBOX:
1831 if (strToInt(argument) == tabular->GetUsebox(actcell))
1832 status |= LyXFunc::ToggleOn;
1834 status |= LyXFunc::ToggleOff;
1836 case LyXTabular::SET_LTFIRSTHEAD:
1837 if (tabular->GetRowOfLTHead(actcell, dummy))
1838 status |= LyXFunc::ToggleOn;
1840 status |= LyXFunc::ToggleOff;
1842 case LyXTabular::SET_LTHEAD:
1843 if (tabular->GetRowOfLTHead(actcell, dummy))
1844 status |= LyXFunc::ToggleOn;
1846 status |= LyXFunc::ToggleOff;
1848 case LyXTabular::SET_LTFOOT:
1849 if (tabular->GetRowOfLTFoot(actcell, dummy))
1850 status |= LyXFunc::ToggleOn;
1852 status |= LyXFunc::ToggleOff;
1854 case LyXTabular::SET_LTLASTFOOT:
1855 if (tabular->GetRowOfLTFoot(actcell, dummy))
1856 status |= LyXFunc::ToggleOn;
1858 status |= LyXFunc::ToggleOff;
1860 case LyXTabular::SET_LTNEWPAGE:
1861 if (tabular->GetLTNewPage(actcell))
1862 status |= LyXFunc::ToggleOn;
1864 status |= LyXFunc::ToggleOff;
1867 status = LyXFunc::Disabled;
1874 bool InsetTabular::copySelection()
1876 if (!hasSelection())
1878 delete paste_tabular;
1880 int sel_col_start, sel_col_end;
1881 int sel_row_start, sel_row_end;
1883 sel_col_start = tabular->column_of_cell(sel_cell_start);
1884 sel_col_end = tabular->column_of_cell(sel_cell_end);
1885 if (sel_col_start > sel_col_end) {
1886 sel_col_start = sel_col_end;
1887 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1889 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1891 int columns = sel_col_end - sel_col_start + 1;
1893 sel_row_start = tabular->row_of_cell(sel_cell_start);
1894 sel_row_end = tabular->row_of_cell(sel_cell_end);
1895 if (sel_row_start > sel_row_end) {
1896 //int tmp tmp = sel_row_start;
1897 //sel_row_start = sel_row_end;
1898 //sel_row_end = tmp;
1899 swap(sel_row_start, sel_row_end);
1901 int rows = sel_row_end - sel_row_start + 1;
1903 paste_tabular = new LyXTabular(this, rows, columns);
1905 if (sel_cell_start > sel_cell_end) {
1906 //int tmp = sel_cell_start;
1907 //sel_cell_start = sel_cell_end;
1908 //sel_cell_end = tmp;
1909 swap(sel_cell_start, sel_cell_end);
1911 for(int i = sel_cell_start, j = 0; i <= sel_cell_end; ++i, ++j) {
1912 while(paste_tabular->row_of_cell(j) <
1913 (tabular->row_of_cell(i)-sel_row_start)) {
1916 while(paste_tabular->row_of_cell(j) >
1917 (tabular->row_of_cell(i)-sel_row_start)) {
1920 *(paste_tabular->GetCellInset(j)) = *(tabular->GetCellInset(i));
1926 bool InsetTabular::pasteSelection(BufferView * bv)
1930 for(int j=0, i=actcell; j<paste_tabular->GetNumberOfCells(); ++j,++i) {
1931 while (paste_tabular->row_of_cell(j) > tabular->row_of_cell(i)-actrow)
1933 if (tabular->GetNumberOfCells() <= i)
1935 while (paste_tabular->row_of_cell(j) < tabular->row_of_cell(i)-actrow)
1937 if (paste_tabular->GetNumberOfCells() <= j)
1939 *(tabular->GetCellInset(i)) = *(paste_tabular->GetCellInset(j));
1940 tabular->GetCellInset(i)->setOwner(this);
1941 tabular->GetCellInset(i)->deleteLyXText(bv);
1947 bool InsetTabular::cutSelection()
1949 if (!hasSelection())
1952 int sel_col_start, sel_col_end;
1953 int sel_row_start, sel_row_end;
1955 sel_col_start = tabular->column_of_cell(sel_cell_start);
1956 sel_col_end = tabular->column_of_cell(sel_cell_end);
1957 if (sel_col_start > sel_col_end) {
1958 sel_col_start = sel_col_end;
1959 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1961 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1963 sel_row_start = tabular->row_of_cell(sel_cell_start);
1964 sel_row_end = tabular->row_of_cell(sel_cell_end);
1965 if (sel_row_start > sel_row_end) {
1966 //int tmp = sel_row_start;
1967 //sel_row_start = sel_row_end;
1968 //sel_row_end = tmp;
1969 swap(sel_row_start, sel_row_end);
1971 if (sel_cell_start > sel_cell_end) {
1972 //int tmp = sel_cell_start;
1973 //sel_cell_start = sel_cell_end;
1974 //sel_cell_end = tmp;
1975 swap(sel_cell_start, sel_cell_end);
1977 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1978 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1979 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();