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 LyXText::text_status st = bv->text->status;
297 cx = nx + tabular->GetBeginningOfTextInCell(cell);
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 cursor.pos(0); // always before the inset!
609 the_locking_inset->InsetButtonPress(bv,
610 x - inset_x, y - inset_y, button);
612 } else if (the_locking_inset) {
613 the_locking_inset->InsetUnlock(bv);
615 the_locking_inset = 0;
616 if (inset_hit && bv->the_locking_inset) {
617 if (ActivateCellInset(bv, x, y, button))
618 the_locking_inset->InsetButtonPress(bv, x - inset_x,
619 y - inset_y, button);
626 void InsetTabular::InsetButtonRelease(BufferView * bv,
627 int x, int y, int button)
630 if (the_locking_inset) {
632 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
633 i->InsetButtonRelease(bv, x, y, button);
637 dialogs_ = bv->owner()->getDialogs();
638 dialogs_->showTabular(this);
641 if (the_locking_inset) {
642 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
645 no_selection = false;
649 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
651 if (the_locking_inset) {
652 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
653 y - inset_y, button);
658 int const old_pos = sel_pos_end;
659 int const old_cell = actcell;
662 sel_pos_end = cursor.pos();
663 sel_cell_end = actcell;
664 if ((sel_cell_end != old_cell) || (old_pos != sel_pos_end))
665 UpdateLocal(bv, SELECTION, false);
668 no_selection = false;
672 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
674 if (the_locking_inset) {
675 the_locking_inset->InsetKeyPress(xke);
681 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
684 UpdatableInset::RESULT
687 no_selection = false;
688 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
689 || (result == DISPATCHED_NOUPDATE)) {
695 if ((action < 0) && arg.empty())
698 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
699 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
701 if (the_locking_inset) {
702 result=the_locking_inset->LocalDispatch(bv, action, arg);
703 if (result == DISPATCHED_NOUPDATE)
705 else if (result == DISPATCHED) {
706 the_locking_inset->ToggleInsetCursor(bv);
707 UpdateLocal(bv, CELL, false);
708 the_locking_inset->ToggleInsetCursor(bv);
710 } else if (result == FINISHED) {
711 if ((action == LFUN_RIGHT) || (action == -1)) {
712 cursor.pos(inset_pos + 1);
715 sel_pos_start = sel_pos_end = cursor.pos();
716 sel_cell_start = sel_cell_end = actcell;
723 bool hs = hasSelection();
727 // Normal chars not handled here
730 // --- Cursor Movements ---------------------------------------------
732 if (tabular->IsLastCellInRow(actcell) && !cellstart(cursor.pos()))
734 moveRight(bv, false);
735 sel_pos_end = cursor.pos();
736 if (!cellstart(cursor.pos())) {
737 if (tabular->right_column_of_cell(sel_cell_start) >
738 tabular->right_column_of_cell(actcell))
739 sel_cell_end = actcell+1;
741 sel_cell_end = actcell;
743 UpdateLocal(bv, SELECTION, false);
746 result = moveRight(bv);
747 sel_pos_start = sel_pos_end = cursor.pos();
748 sel_cell_start = sel_cell_end = actcell;
750 UpdateLocal(bv, SELECTION, false);
753 if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos()))
756 sel_pos_end = cursor.pos();
757 if (cellstart(cursor.pos())) {
758 if (tabular->column_of_cell(sel_cell_start) >=
759 tabular->column_of_cell(actcell))
760 sel_cell_end = actcell;
762 sel_cell_end = actcell-1;
764 UpdateLocal(bv, SELECTION, false);
767 result = moveLeft(bv);
768 sel_pos_start = sel_pos_end = cursor.pos();
769 sel_cell_start = sel_cell_end = actcell;
771 UpdateLocal(bv, SELECTION, false);
775 int const ocell = actcell;
777 sel_pos_end = cursor.pos();
778 if ((ocell == sel_cell_end) ||
779 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
780 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
782 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
783 UpdateLocal(bv, SELECTION, false);
787 result = moveDown(bv);
788 sel_pos_start = sel_pos_end = cursor.pos();
789 sel_cell_start = sel_cell_end = actcell;
791 UpdateLocal(bv, SELECTION, false);
795 int const ocell = actcell;
797 sel_pos_end = cursor.pos();
798 if ((ocell == sel_cell_end) ||
799 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
800 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
802 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
803 UpdateLocal(bv, SELECTION, false);
808 sel_pos_start = sel_pos_end = cursor.pos();
809 sel_cell_start = sel_cell_end = actcell;
811 UpdateLocal(bv, SELECTION, false);
823 if (the_locking_inset) {
824 UnlockInsetInInset(bv, the_locking_inset);
825 the_locking_inset = 0;
827 if (action == LFUN_TAB)
831 sel_pos_start = sel_pos_end = cursor.pos();
832 sel_cell_start = sel_cell_end = actcell;
834 UpdateLocal(bv, SELECTION, false);
836 case LFUN_LAYOUT_TABULAR:
838 dialogs_ = bv->owner()->getDialogs();
839 dialogs_->showTabular(this);
842 case LFUN_TABULAR_FEATURE:
843 if (!TabularFeatures(bv, arg))
844 result = UNDISPATCHED;
847 if (!copySelection())
849 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
851 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
852 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
854 bv->text->cursor.par()->previous,
855 bv->text->cursor.par()->next
859 UpdateLocal(bv, INIT, true);
864 bv->text->FinishUndo();
868 if (!hasPasteBuffer())
870 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
872 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
873 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
875 bv->text->cursor.par()->previous,
876 bv->text->cursor.par()->next
880 UpdateLocal(bv, INIT, true);
883 result = UNDISPATCHED;
886 if (result!=FINISHED) {
887 if (!the_locking_inset) {
889 if (ocell != actcell)
890 bview->getOwner()->getPopups().updateFormTabular();
895 bv->unlockInset(this);
900 int InsetTabular::Latex(Buffer const * buf, ostream & os,
901 bool fragile, bool fp) const
903 return tabular->Latex(buf, os, fragile, fp);
907 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
909 // This should be changed to a real ascii export
910 return tabular->Latex(buf, os, false, false);
914 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
920 int InsetTabular::DocBook(Buffer const *, ostream &) const
926 void InsetTabular::Validate(LaTeXFeatures & features) const
928 tabular->Validate(features);
932 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
933 LyXFont const & font,
939 bool changed = false;
941 for(int i = 0; i < tabular->rows(); ++i) {
942 maxAsc = maxDesc = 0;
943 for(int j= 0; j < tabular->columns(); ++j) {
944 if (tabular->IsPartOfMultiColumn(i,j))
947 inset = tabular->GetCellInset(cell);
949 inset->update(bv, font, false);
950 maxAsc = max(maxAsc, inset->ascent(bv, font));
951 maxDesc = max(maxDesc, inset->descent(bv, font));
952 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
954 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
955 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
961 void InsetTabular::GetCursorPos(BufferView *,
962 unsigned long & x, unsigned long & y) const
964 x = cursor.x() - top_x;
969 void InsetTabular::ToggleInsetCursor(BufferView * bv)
971 if (the_locking_inset) {
972 the_locking_inset->ToggleInsetCursor(bv);
976 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
978 int const asc = lyxfont::maxAscent(font);
979 int const desc = lyxfont::maxDescent(font);
982 bv->hideLockedInsetCursor();
984 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
985 cursor_visible = !cursor_visible;
989 void InsetTabular::ShowInsetCursor(BufferView * bv)
991 if (!cursor_visible) {
992 LyXFont font; // = GetFont(par, cursor.pos);
994 int const asc = lyxfont::maxAscent(font);
995 int const desc = lyxfont::maxDescent(font);
996 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
997 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
998 cursor_visible = true;
1003 void InsetTabular::HideInsetCursor(BufferView * bv)
1005 if (cursor_visible) {
1006 bv->hideLockedInsetCursor();
1007 cursor_visible = false;
1009 // if (cursor_visible)
1010 // ToggleInsetCursor(bv);
1014 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1019 actcell = actrow = actcol = 0;
1020 int ly = tabular->GetDescentOfRow(actrow);
1022 // first search the right row
1023 while((ly < y) && (actrow < tabular->rows())) {
1024 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1025 tabular->GetAscentOfRow(actrow+1) +
1026 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1029 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1031 actcell = tabular->GetCellNumber(actrow, actcol);
1033 // now search the right column
1034 int lx = tabular->GetWidthOfColumn(actcell) -
1035 tabular->GetAdditionalWidth(actcell);
1036 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
1037 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1038 tabular->GetAdditionalWidth(actcell - 1));
1041 if ((lx - (tabular->GetWidthOfColumn(actcell) / 2)) < x) {
1042 cursor.x(lx + top_x - 2);
1045 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1051 int InsetTabular::getCellXPos(int cell) const
1055 for(; !tabular->IsFirstCellInRow(c); --c)
1057 int lx = tabular->GetWidthOfColumn(cell);
1058 for(; (c < cell); ++c) {
1059 lx += tabular->GetWidthOfColumn(c);
1061 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1065 void InsetTabular::resetPos(BufferView * bv) const
1069 actcol = tabular->column_of_cell(actcell);
1074 for(; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1075 if (tabular->IsLastCellInRow(cell)) {
1076 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1077 tabular->GetAscentOfRow(actrow + 1) +
1078 tabular->GetAdditionalHeight(cell + 1));
1082 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1083 cursor.x(getCellXPos(actcell) + offset);
1084 if (((cursor.x() - offset) > 20) &&
1085 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1086 (bv->workWidth()-20)))
1088 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1089 UpdateLocal(bv, FULL, false);
1090 } else if ((cursor.x() - offset) < 20) {
1091 scroll(bv, 20 - cursor.x() + offset);
1092 UpdateLocal(bv, FULL, false);
1093 } else if (!cellstart(cursor.pos())) {
1094 LyXFont font(LyXFont::ALL_SANE);
1095 cursor.x(cursor.x() + tabular->GetCellInset(actcell)->width(bv,font) +
1096 tabular->GetBeginningOfTextInCell(actcell));
1098 if ((!the_locking_inset ||
1099 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1100 (actcell != oldcell)) {
1101 dialogs_ = bv->owner()->getDialogs();
1102 dialogs_->updateTabular(const_cast<InsetTabular *>(this));
1108 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1110 if (!cellstart(cursor.pos())) {
1111 if (tabular->IsLastCell(actcell))
1114 cursor.pos((cursor.pos() + 1) % 2);
1116 if (ActivateCellInset(bv))
1118 } else { // before the inset
1119 cursor.pos((cursor.pos() + 1) % 2);
1122 return DISPATCHED_NOUPDATE;
1126 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1128 if (!cursor.pos()) {
1133 cursor.pos((cursor.pos() - 1) % 2);
1134 if (!cellstart(cursor.pos())) {
1136 } else if (lock) { // behind the inset
1137 if (ActivateCellInset(bv, 0, 0, 0, true))
1141 return DISPATCHED_NOUPDATE;
1145 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv)
1147 int const ocell = actcell;
1148 actcell = tabular->GetCellAbove(actcell);
1149 if (actcell == ocell) // we moved out of the inset
1152 return DISPATCHED_NOUPDATE;
1156 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv)
1158 int const ocell = actcell;
1159 actcell = tabular->GetCellBelow(actcell);
1160 if (actcell == ocell) // we moved out of the inset
1163 return DISPATCHED_NOUPDATE;
1167 bool InsetTabular::moveNextCell(BufferView * bv)
1169 if (tabular->IsLastCell(actcell))
1172 cursor.pos((cursor.pos() + 1) % 2);
1173 if (!cellstart(cursor.pos()))
1174 cursor.pos((cursor.pos() + 1) % 2);
1180 bool InsetTabular::movePrevCell(BufferView * bv)
1182 if (!actcell) // first cell
1185 cursor.pos((cursor.pos() - 1) % 2);
1186 if (cellstart(cursor.pos()))
1187 cursor.pos((cursor.pos() - 1) % 2);
1193 bool InsetTabular::Delete()
1199 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1201 if (the_locking_inset)
1202 the_locking_inset->SetFont(bv, font, tall);
1206 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1208 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1211 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1212 string const tmp = tabularFeatures[i].feature;
1214 if (tmp == what.substr(0, tmp.length())) {
1215 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1216 //tabularFeatures[i].feature.length())) {
1217 action = tabularFeatures[i].action;
1221 if (action == LyXTabular::LAST_ACTION)
1225 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1226 TabularFeatures(bv, action, val);
1231 void InsetTabular::TabularFeatures(BufferView * bv,
1232 LyXTabular::Feature feature,
1233 string const & value)
1242 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1243 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1248 case LyXTabular::M_ALIGN_LEFT:
1249 case LyXTabular::ALIGN_LEFT:
1250 setAlign=LYX_ALIGN_LEFT;
1252 case LyXTabular::M_ALIGN_RIGHT:
1253 case LyXTabular::ALIGN_RIGHT:
1254 setAlign=LYX_ALIGN_RIGHT;
1256 case LyXTabular::M_ALIGN_CENTER:
1257 case LyXTabular::ALIGN_CENTER:
1258 setAlign=LYX_ALIGN_CENTER;
1260 case LyXTabular::M_VALIGN_TOP:
1261 case LyXTabular::VALIGN_TOP:
1262 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1264 case LyXTabular::M_VALIGN_BOTTOM:
1265 case LyXTabular::VALIGN_BOTTOM:
1266 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1268 case LyXTabular::M_VALIGN_CENTER:
1269 case LyXTabular::VALIGN_CENTER:
1270 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1275 if (hasSelection()) {
1276 sel_col_start = tabular->column_of_cell(sel_cell_start);
1277 sel_col_end = tabular->column_of_cell(sel_cell_end);
1278 if (sel_col_start > sel_col_end) {
1279 sel_col_end = sel_col_start;
1280 sel_col_start = tabular->column_of_cell(sel_cell_end);
1282 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1285 sel_row_start = tabular->row_of_cell(sel_cell_start);
1286 sel_row_end = tabular->row_of_cell(sel_cell_end);
1287 if (sel_row_start > sel_row_end) {
1288 //int tmp = sel_row_start;
1289 //sel_row_start = sel_row_end;
1290 //sel_row_end = tmp;
1291 swap(sel_row_start, sel_row_end);
1294 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1295 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1297 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1299 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1300 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1302 bv->text->cursor.par()->previous,
1303 bv->text->cursor.par()->next
1307 int row = tabular->row_of_cell(actcell);
1308 int column = tabular->column_of_cell(actcell);
1312 case LyXTabular::SET_PWIDTH:
1314 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1315 tabular->SetColumnPWidth(actcell,value);
1317 for (int i=0; i < tabular->rows(); ++i) {
1318 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1321 UpdateLocal(bv, INIT, true);
1325 case LyXTabular::SET_MPWIDTH:
1327 bool const update = (tabular->GetPWidth(actcell) != value);
1328 tabular->SetMColumnPWidth(actcell,value);
1330 for (int i=0; i < tabular->rows(); ++i) {
1331 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1334 UpdateLocal(bv, INIT, true);
1338 case LyXTabular::SET_SPECIAL_COLUMN:
1339 case LyXTabular::SET_SPECIAL_MULTI:
1340 tabular->SetAlignSpecial(actcell,value,feature);
1342 case LyXTabular::APPEND_ROW:
1343 // append the row into the tabular
1344 UnlockInsetInInset(bv, the_locking_inset);
1345 tabular->AppendRow(actcell);
1346 UpdateLocal(bv, INIT, true);
1348 case LyXTabular::APPEND_COLUMN:
1349 // append the column into the tabular
1350 tabular->AppendColumn(actcell);
1351 actcell = tabular->GetCellNumber(row, column);
1352 UpdateLocal(bv, INIT, true);
1354 case LyXTabular::DELETE_ROW:
1355 tabular->DeleteRow(tabular->row_of_cell(actcell));
1356 if ((row+1) > tabular->rows())
1358 actcell = tabular->GetCellNumber(row, column);
1359 UpdateLocal(bv, INIT, true);
1361 case LyXTabular::DELETE_COLUMN:
1362 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1363 if ((column+1) > tabular->columns())
1365 actcell = tabular->GetCellNumber(row, column);
1366 UpdateLocal(bv, INIT, true);
1368 case LyXTabular::M_TOGGLE_LINE_TOP:
1370 case LyXTabular::TOGGLE_LINE_TOP:
1371 lineSet = !tabular->TopLine(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->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1375 UpdateLocal(bv, INIT, true);
1378 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1380 case LyXTabular::TOGGLE_LINE_BOTTOM:
1381 lineSet = !tabular->BottomLine(actcell, flag);
1382 for(i=sel_row_start; i<=sel_row_end; ++i)
1383 for(j=sel_col_start; j<=sel_col_end; ++j)
1384 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1386 UpdateLocal(bv, INIT, true);
1389 case LyXTabular::M_TOGGLE_LINE_LEFT:
1391 case LyXTabular::TOGGLE_LINE_LEFT:
1392 lineSet = !tabular->LeftLine(actcell, flag);
1393 for(i=sel_row_start; i<=sel_row_end; ++i)
1394 for(j=sel_col_start; j<=sel_col_end; ++j)
1395 tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1397 UpdateLocal(bv, INIT, true);
1400 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1402 case LyXTabular::TOGGLE_LINE_RIGHT:
1403 lineSet = !tabular->RightLine(actcell, flag);
1404 for(i=sel_row_start; i<=sel_row_end; ++i)
1405 for(j=sel_col_start; j<=sel_col_end; ++j)
1406 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1408 UpdateLocal(bv, INIT, true);
1410 case LyXTabular::M_ALIGN_LEFT:
1411 case LyXTabular::M_ALIGN_RIGHT:
1412 case LyXTabular::M_ALIGN_CENTER:
1414 case LyXTabular::ALIGN_LEFT:
1415 case LyXTabular::ALIGN_RIGHT:
1416 case LyXTabular::ALIGN_CENTER:
1417 for(i = sel_row_start; i <= sel_row_end; ++i)
1418 for(j = sel_col_start; j <= sel_col_end; ++j)
1419 tabular->SetAlignment(tabular->GetCellNumber(i, j), setAlign,
1422 UpdateLocal(bv, INIT, true);
1424 UpdateLocal(bv, CELL, true);
1426 case LyXTabular::M_VALIGN_TOP:
1427 case LyXTabular::M_VALIGN_BOTTOM:
1428 case LyXTabular::M_VALIGN_CENTER:
1430 case LyXTabular::VALIGN_TOP:
1431 case LyXTabular::VALIGN_BOTTOM:
1432 case LyXTabular::VALIGN_CENTER:
1433 for(i = sel_row_start; i <= sel_row_end; ++i)
1434 for(j = sel_col_start; j <= sel_col_end; ++j)
1435 tabular->SetVAlignment(tabular->GetCellNumber(i, j),
1438 UpdateLocal(bv, INIT, true);
1440 UpdateLocal(bv, CELL, true);
1442 case LyXTabular::MULTICOLUMN:
1444 if (sel_row_start != sel_row_end) {
1445 WriteAlert(_("Impossible Operation!"),
1446 _("Multicolumns can only be horizontally."),
1450 // just multicol for one Single Cell
1451 if (!hasSelection()) {
1452 // check wether we are completly in a multicol
1453 if (tabular->IsMultiColumn(actcell)) {
1454 tabular->UnsetMultiColumn(actcell);
1455 UpdateLocal(bv, INIT, true);
1457 tabular->SetMultiColumn(actcell, 1);
1458 UpdateLocal(bv, CELL, true);
1462 // we have a selection so this means we just add all this
1463 // cells to form a multicolumn cell
1467 if (sel_cell_start > sel_cell_end) {
1468 s_start = sel_cell_end;
1469 s_end = sel_cell_start;
1471 s_start = sel_cell_start;
1472 s_end = sel_cell_end;
1474 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1477 sel_cell_end = sel_cell_start;
1478 sel_pos_end = sel_pos_start;
1479 UpdateLocal(bv, INIT, true);
1482 case LyXTabular::SET_ALL_LINES:
1484 case LyXTabular::UNSET_ALL_LINES:
1485 for(i=sel_row_start; i<=sel_row_end; ++i)
1486 for(j=sel_col_start; j<=sel_col_end; ++j)
1487 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1488 UpdateLocal(bv, INIT, true);
1490 case LyXTabular::SET_LONGTABULAR:
1491 tabular->SetLongTabular(true);
1492 UpdateLocal(bv, INIT, true); // because this toggles displayed
1494 case LyXTabular::UNSET_LONGTABULAR:
1495 tabular->SetLongTabular(false);
1496 UpdateLocal(bv, INIT, true); // because this toggles displayed
1498 case LyXTabular::SET_ROTATE_TABULAR:
1499 tabular->SetRotateTabular(true);
1501 case LyXTabular::UNSET_ROTATE_TABULAR:
1502 tabular->SetRotateTabular(false);
1504 case LyXTabular::SET_ROTATE_CELL:
1505 for(i=sel_row_start; i<=sel_row_end; ++i)
1506 for(j=sel_col_start; j<=sel_col_end; ++j)
1507 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1509 case LyXTabular::UNSET_ROTATE_CELL:
1510 for(i = sel_row_start; i <= sel_row_end; ++i)
1511 for(j = sel_col_start; j <= sel_col_end; ++j)
1512 tabular->SetRotateCell(tabular->GetCellNumber(i, j), false);
1514 case LyXTabular::SET_USEBOX:
1516 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1517 if (val == tabular->GetUsebox(actcell))
1518 val = LyXTabular::BOX_NONE;
1519 for(i = sel_row_start; i <= sel_row_end; ++i)
1520 for(j = sel_col_start; j <= sel_col_end; ++j)
1521 tabular->SetUsebox(tabular->GetCellNumber(i, j), val);
1524 case LyXTabular::SET_LTFIRSTHEAD:
1525 tabular->SetLTHead(actcell, true);
1527 case LyXTabular::SET_LTHEAD:
1528 tabular->SetLTHead(actcell, false);
1530 case LyXTabular::SET_LTFOOT:
1531 tabular->SetLTFoot(actcell, false);
1533 case LyXTabular::SET_LTLASTFOOT:
1534 tabular->SetLTFoot(actcell, true);
1536 case LyXTabular::SET_LTNEWPAGE:
1537 what = !tabular->GetLTNewPage(actcell);
1538 tabular->SetLTNewPage(actcell, what);
1540 // dummy stuff just to avoid warnings
1541 case LyXTabular::LAST_ACTION:
1547 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1550 // the cursor.pos has to be before the inset so if it isn't now just
1551 // reset the curor pos first!
1552 if (!cellstart(cursor.pos())) {
1556 UpdatableInset * inset =
1557 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1558 LyXFont font(LyXFont::ALL_SANE);
1560 x = inset->x() + inset->width(bv, font);
1561 y = inset->descent(bv, font);
1563 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1564 inset_y = cursor.y();
1565 inset->Edit(bv, x - inset_x, y - inset_y, button);
1566 if (!the_locking_inset)
1568 UpdateLocal(bv, CELL, false);
1569 return (the_locking_inset != 0);
1573 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1575 InsetText * inset = tabular->GetCellInset(actcell);
1578 if (!cellstart(cursor.pos())) {
1579 return (((x + top_x) < cursor.x()) &&
1580 ((x + top_x) > (cursor.x() - inset->width(bv,
1581 LyXFont(LyXFont::ALL_SANE)))));
1583 int x2 = cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1584 return ((x1 > x2) &&
1585 (x1 < (x2 + inset->width(bv, LyXFont(LyXFont::ALL_SANE)))));
1590 // This returns paperWidth() if the cell-width is unlimited or the width
1591 // in pixels if we have a pwidth for this cell.
1592 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1594 string const s = tabular->GetPWidth(cell);
1598 return VSpace(s).inPixels(0, 0);
1602 int InsetTabular::getMaxWidth(Painter & pain,
1603 UpdatableInset const * inset) const
1605 int const n = tabular->GetNumberOfCells();
1607 for(; cell < n; ++cell) {
1608 if (tabular->GetCellInset(cell) == inset)
1613 int w = GetMaxWidthOfCell(pain, cell);
1615 // because the inset then subtracts it's top_x and owner->x()
1616 w += (inset->x() - top_x);
1621 void InsetTabular::resizeLyXText(BufferView *) const
1627 LyXText * InsetTabular::getLyXText(BufferView * bv) const
1629 if (the_locking_inset)
1630 return the_locking_inset->getLyXText(bv);
1631 return Inset::getLyXText(bv);
1635 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1637 if (the_locking_inset) {
1638 InsetTabular * i = static_cast<InsetTabular *>
1639 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1641 i->OpenLayoutDialog(bv);
1645 dialogs_ = bv->owner()->getDialogs();
1646 dialogs_->showTabular(const_cast<InsetTabular *>(this));
1650 // functions returns:
1654 // 3 ... toggled off
1656 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1658 int action = LyXTabular::LAST_ACTION;
1659 LyXFunc::func_status status = LyXFunc::OK;
1662 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1663 string const tmp = tabularFeatures[i].feature;
1664 if (tmp == what.substr(0, tmp.length())) {
1665 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1666 // tabularFeatures[i].feature.length())) {
1667 action = tabularFeatures[i].action;
1671 if (action == LyXTabular::LAST_ACTION)
1672 return LyXFunc::Unknown;
1674 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1676 int sel_row_start, sel_row_end;
1680 if (hasSelection()) {
1681 sel_row_start = tabular->row_of_cell(sel_cell_start);
1682 sel_row_end = tabular->row_of_cell(sel_cell_end);
1683 if (sel_row_start > sel_row_end) {
1684 //int tmp = sel_row_start;
1685 //sel_row_start = sel_row_end;
1686 //sel_row_end = tmp;
1687 swap(sel_row_start, sel_row_end);
1690 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1694 case LyXTabular::SET_PWIDTH:
1695 case LyXTabular::SET_MPWIDTH:
1696 case LyXTabular::SET_SPECIAL_COLUMN:
1697 case LyXTabular::SET_SPECIAL_MULTI:
1698 status |= LyXFunc::Disabled;
1701 case LyXTabular::APPEND_ROW:
1702 case LyXTabular::APPEND_COLUMN:
1703 case LyXTabular::DELETE_ROW:
1704 case LyXTabular::DELETE_COLUMN:
1705 case LyXTabular::SET_ALL_LINES:
1706 case LyXTabular::UNSET_ALL_LINES:
1707 status |= LyXFunc::OK;
1710 case LyXTabular::MULTICOLUMN:
1711 if (tabular->IsMultiColumn(actcell))
1712 status |= LyXFunc::ToggleOn;
1714 status |= LyXFunc::ToggleOff;
1716 case LyXTabular::M_TOGGLE_LINE_TOP:
1718 case LyXTabular::TOGGLE_LINE_TOP:
1719 if (tabular->TopLine(actcell, flag))
1720 status |= LyXFunc::ToggleOn;
1722 status |= LyXFunc::ToggleOff;
1724 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1726 case LyXTabular::TOGGLE_LINE_BOTTOM:
1727 if (tabular->BottomLine(actcell, flag))
1728 status |= LyXFunc::ToggleOn;
1730 status |= LyXFunc::ToggleOff;
1732 case LyXTabular::M_TOGGLE_LINE_LEFT:
1734 case LyXTabular::TOGGLE_LINE_LEFT:
1735 if (tabular->LeftLine(actcell, flag))
1736 status |= LyXFunc::ToggleOn;
1738 status |= LyXFunc::ToggleOff;
1740 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1742 case LyXTabular::TOGGLE_LINE_RIGHT:
1743 if (tabular->RightLine(actcell, flag))
1744 status |= LyXFunc::ToggleOn;
1746 status |= LyXFunc::ToggleOff;
1748 case LyXTabular::M_ALIGN_LEFT:
1750 case LyXTabular::ALIGN_LEFT:
1751 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1752 status |= LyXFunc::ToggleOn;
1754 status |= LyXFunc::ToggleOff;
1756 case LyXTabular::M_ALIGN_RIGHT:
1758 case LyXTabular::ALIGN_RIGHT:
1759 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1760 status |= LyXFunc::ToggleOn;
1762 status |= LyXFunc::ToggleOff;
1764 case LyXTabular::M_ALIGN_CENTER:
1766 case LyXTabular::ALIGN_CENTER:
1767 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1768 status |= LyXFunc::ToggleOn;
1770 status |= LyXFunc::ToggleOff;
1772 case LyXTabular::M_VALIGN_TOP:
1774 case LyXTabular::VALIGN_TOP:
1775 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1776 status |= LyXFunc::ToggleOn;
1778 status |= LyXFunc::ToggleOff;
1780 case LyXTabular::M_VALIGN_BOTTOM:
1782 case LyXTabular::VALIGN_BOTTOM:
1783 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1784 status |= LyXFunc::ToggleOn;
1786 status |= LyXFunc::ToggleOff;
1788 case LyXTabular::M_VALIGN_CENTER:
1790 case LyXTabular::VALIGN_CENTER:
1791 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1792 status |= LyXFunc::ToggleOn;
1794 status |= LyXFunc::ToggleOff;
1796 case LyXTabular::SET_LONGTABULAR:
1797 if (tabular->IsLongTabular())
1798 status |= LyXFunc::ToggleOn;
1800 status |= LyXFunc::ToggleOff;
1802 case LyXTabular::UNSET_LONGTABULAR:
1803 if (!tabular->IsLongTabular())
1804 status |= LyXFunc::ToggleOn;
1806 status |= LyXFunc::ToggleOff;
1808 case LyXTabular::SET_ROTATE_TABULAR:
1809 if (tabular->GetRotateTabular())
1810 status |= LyXFunc::ToggleOn;
1812 status |= LyXFunc::ToggleOff;
1814 case LyXTabular::UNSET_ROTATE_TABULAR:
1815 if (!tabular->GetRotateTabular())
1816 status |= LyXFunc::ToggleOn;
1818 status |= LyXFunc::ToggleOff;
1820 case LyXTabular::SET_ROTATE_CELL:
1821 if (tabular->GetRotateCell(actcell))
1822 status |= LyXFunc::ToggleOn;
1824 status |= LyXFunc::ToggleOff;
1826 case LyXTabular::UNSET_ROTATE_CELL:
1827 if (!tabular->GetRotateCell(actcell))
1828 status |= LyXFunc::ToggleOn;
1830 status |= LyXFunc::ToggleOff;
1832 case LyXTabular::SET_USEBOX:
1833 if (strToInt(argument) == tabular->GetUsebox(actcell))
1834 status |= LyXFunc::ToggleOn;
1836 status |= LyXFunc::ToggleOff;
1838 case LyXTabular::SET_LTFIRSTHEAD:
1839 if (tabular->GetRowOfLTHead(actcell, dummy))
1840 status |= LyXFunc::ToggleOn;
1842 status |= LyXFunc::ToggleOff;
1844 case LyXTabular::SET_LTHEAD:
1845 if (tabular->GetRowOfLTHead(actcell, dummy))
1846 status |= LyXFunc::ToggleOn;
1848 status |= LyXFunc::ToggleOff;
1850 case LyXTabular::SET_LTFOOT:
1851 if (tabular->GetRowOfLTFoot(actcell, dummy))
1852 status |= LyXFunc::ToggleOn;
1854 status |= LyXFunc::ToggleOff;
1856 case LyXTabular::SET_LTLASTFOOT:
1857 if (tabular->GetRowOfLTFoot(actcell, dummy))
1858 status |= LyXFunc::ToggleOn;
1860 status |= LyXFunc::ToggleOff;
1862 case LyXTabular::SET_LTNEWPAGE:
1863 if (tabular->GetLTNewPage(actcell))
1864 status |= LyXFunc::ToggleOn;
1866 status |= LyXFunc::ToggleOff;
1869 status = LyXFunc::Disabled;
1876 bool InsetTabular::copySelection()
1878 if (!hasSelection())
1880 delete paste_tabular;
1882 int sel_col_start, sel_col_end;
1883 int sel_row_start, sel_row_end;
1885 sel_col_start = tabular->column_of_cell(sel_cell_start);
1886 sel_col_end = tabular->column_of_cell(sel_cell_end);
1887 if (sel_col_start > sel_col_end) {
1888 sel_col_start = sel_col_end;
1889 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1891 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1893 int columns = sel_col_end - sel_col_start + 1;
1895 sel_row_start = tabular->row_of_cell(sel_cell_start);
1896 sel_row_end = tabular->row_of_cell(sel_cell_end);
1897 if (sel_row_start > sel_row_end) {
1898 //int tmp tmp = sel_row_start;
1899 //sel_row_start = sel_row_end;
1900 //sel_row_end = tmp;
1901 swap(sel_row_start, sel_row_end);
1903 int rows = sel_row_end - sel_row_start + 1;
1905 paste_tabular = new LyXTabular(this, rows, columns);
1907 if (sel_cell_start > sel_cell_end) {
1908 //int tmp = sel_cell_start;
1909 //sel_cell_start = sel_cell_end;
1910 //sel_cell_end = tmp;
1911 swap(sel_cell_start, sel_cell_end);
1913 for(int i = sel_cell_start, j = 0; i <= sel_cell_end; ++i, ++j) {
1914 while(paste_tabular->row_of_cell(j) <
1915 (tabular->row_of_cell(i)-sel_row_start)) {
1918 while(paste_tabular->row_of_cell(j) >
1919 (tabular->row_of_cell(i)-sel_row_start)) {
1922 *(paste_tabular->GetCellInset(j)) = *(tabular->GetCellInset(i));
1928 bool InsetTabular::pasteSelection(BufferView * bv)
1932 for(int j=0, i=actcell; j<paste_tabular->GetNumberOfCells(); ++j,++i) {
1933 while (paste_tabular->row_of_cell(j) > tabular->row_of_cell(i)-actrow)
1935 if (tabular->GetNumberOfCells() <= i)
1937 while (paste_tabular->row_of_cell(j) < tabular->row_of_cell(i)-actrow)
1939 if (paste_tabular->GetNumberOfCells() <= j)
1941 *(tabular->GetCellInset(i)) = *(paste_tabular->GetCellInset(j));
1942 tabular->GetCellInset(i)->setOwner(this);
1943 tabular->GetCellInset(i)->deleteLyXText(bv);
1949 bool InsetTabular::cutSelection()
1951 if (!hasSelection())
1954 int sel_col_start, sel_col_end;
1955 int sel_row_start, sel_row_end;
1957 sel_col_start = tabular->column_of_cell(sel_cell_start);
1958 sel_col_end = tabular->column_of_cell(sel_cell_end);
1959 if (sel_col_start > sel_col_end) {
1960 sel_col_start = sel_col_end;
1961 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1963 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1965 sel_row_start = tabular->row_of_cell(sel_cell_start);
1966 sel_row_end = tabular->row_of_cell(sel_cell_end);
1967 if (sel_row_start > sel_row_end) {
1968 //int tmp = sel_row_start;
1969 //sel_row_start = sel_row_end;
1970 //sel_row_end = tmp;
1971 swap(sel_row_start, sel_row_end);
1973 if (sel_cell_start > sel_cell_end) {
1974 //int tmp = sel_cell_start;
1975 //sel_cell_start = sel_cell_end;
1976 //sel_cell_end = tmp;
1977 swap(sel_cell_start, sel_cell_end);
1979 for(int i = sel_row_start; i <= sel_row_end; ++i) {
1980 for(int j = sel_col_start; j <= sel_col_end; ++j) {
1981 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();