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 const & 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;
139 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
142 tabular = new LyXTabular(this, *(tab.tabular));
143 the_locking_inset = 0;
144 locked = no_selection = cursor_visible = false;
149 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
154 InsetTabular::~InsetTabular()
161 Inset * InsetTabular::Clone(Buffer const & buf) const
163 InsetTabular * t = new InsetTabular(*this, buf);
165 t->tabular = tabular->Clone(t);
170 void InsetTabular::Write(Buffer const * buf, ostream & os) const
172 os << " Tabular" << endl;
173 tabular->Write(buf, os);
177 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
179 bool old_format = (lex.GetString() == "\\LyXTable");
184 tabular = new LyXTabular(buf, this, lex);
192 token = lex.GetString();
193 while (lex.IsOK() && (token != "\\end_inset")) {
195 token = lex.GetString();
197 if (token != "\\end_inset") {
198 lex.printError("Missing \\end_inset at this point. "
204 int InsetTabular::ascent(BufferView *, LyXFont const &) const
206 return tabular->GetAscentOfRow(0);
210 int InsetTabular::descent(BufferView *, LyXFont const &) const
212 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
216 int InsetTabular::width(BufferView *, LyXFont const &) const
218 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
222 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
223 float & x, bool cleared) const
225 Painter & pain = bv->painter();
230 UpdatableInset::draw(bv, font, baseline, x, cleared);
231 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
232 (top_x != int(x)) || (top_baseline != baseline))) {
233 int h = ascent(bv, font) + descent(bv, font);
234 int tx = display() || !owner() ? 0 : top_x;
235 int w = tx ? width(bv, font) : pain.paperWidth();
236 int ty = baseline - ascent(bv, font);
240 if ((ty + h) > pain.paperHeight())
241 h = pain.paperHeight();
242 if ((top_x + w) > pain.paperWidth())
243 w = pain.paperWidth();
244 pain.fillRectangle(tx, ty, w, h);
249 top_baseline = baseline;
250 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
253 x += ADD_TO_TABULAR_WIDTH;
255 for(i = 0; i < tabular->rows(); ++i) {
257 dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
258 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight();
259 for(j = 0; j < tabular->columns(); ++j) {
260 if (tabular->IsPartOfMultiColumn(i, j))
262 cx = nx + tabular->GetBeginningOfTextInCell(cell);
265 DrawCellSelection(pain, nx, baseline, i, j, cell);
266 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
268 DrawCellLines(pain, nx, baseline, i, cell);
270 nx += tabular->GetWidthOfColumn(cell);
273 baseline += tabular->GetDescentOfRow(i) +
274 tabular->GetAscentOfRow(i + 1) +
275 tabular->GetAdditionalHeight(cell);
277 } else if (need_update == CELL) {
279 for(i = 0; (cell < actcell) && (i < tabular->rows()); ++i) {
280 for(j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
281 if (tabular->IsPartOfMultiColumn(i, j))
283 nx += tabular->GetWidthOfColumn(cell);
286 if (tabular->row_of_cell(cell) > i) {
288 baseline += tabular->GetDescentOfRow(i) +
289 tabular->GetAscentOfRow(i + 1) +
290 tabular->GetAdditionalHeight(cell);
293 i = tabular->row_of_cell(actcell);
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;
441 sel_pos_start = sel_pos_end = cursor.pos();
442 sel_cell_start = sel_cell_end = actcell;
443 bv->text->FinishUndo();
444 if (InsetHit(bv, x, y)) {
445 ActivateCellInset(bv, x, y, button);
447 UpdateLocal(bv, NONE, false);
448 // bv->getOwner()->getPopups().updateFormTabular();
452 void InsetTabular::InsetUnlock(BufferView * bv)
454 if (the_locking_inset) {
455 the_locking_inset->InsetUnlock(bv);
456 the_locking_inset = 0;
459 no_selection = false;
462 if (scroll() || hasSelection()) {
466 sel_pos_start = sel_pos_end = 0;
467 sel_cell_start = sel_cell_end = 0;
469 UpdateLocal(bv, FULL, false);
474 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
475 bool mark_dirty) const
479 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
480 if (locked && (what != NONE))
485 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
487 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
491 if (inset == tabular->GetCellInset(actcell)) {
492 lyxerr[Debug::INSETS] << "OK" << endl;
493 the_locking_inset = tabular->GetCellInset(actcell);
495 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
496 inset_y = cursor.y();
497 inset_pos = cursor.pos();
499 } else if (the_locking_inset && (the_locking_inset == inset)) {
500 if (cursor.pos() == inset_pos) {
501 lyxerr[Debug::INSETS] << "OK" << endl;
503 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
504 inset_y = cursor.y();
506 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
508 } else if (the_locking_inset) {
509 lyxerr[Debug::INSETS] << "MAYBE" << endl;
510 return the_locking_inset->LockInsetInInset(bv, inset);
512 lyxerr[Debug::INSETS] << "NOT OK" << endl;
517 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
520 if (!the_locking_inset)
522 if (the_locking_inset == inset) {
523 the_locking_inset->InsetUnlock(bv);
524 the_locking_inset = 0;
526 moveRight(bv, false);
527 ShowInsetCursor(bv, false);
528 UpdateLocal(bv, CELL, false);
531 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
532 if (inset->LyxCode() == TABULAR_CODE &&
533 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
535 bv->owner()->getDialogs()->updateTabular(this);
544 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
546 if (!the_locking_inset)
548 if (the_locking_inset != inset)
549 return the_locking_inset->UpdateInsetInInset(bv, inset);
550 UpdateLocal(bv, CELL, false);
555 unsigned int InsetTabular::InsetInInsetY()
557 if (!the_locking_inset)
560 return (inset_y + the_locking_inset->InsetInInsetY());
564 UpdatableInset * InsetTabular::GetLockingInset()
566 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
570 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
574 if (the_locking_inset)
575 return the_locking_inset->GetFirstLockingInsetOfType(c);
580 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
582 if (the_locking_inset)
583 return the_locking_inset->InsertInset(bv, inset);
588 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
590 if (hasSelection()) {
591 sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
592 UpdateLocal(bv, SELECTION, false);
594 no_selection = false;
596 int const ocell = actcell;
597 int const orow = actrow;
602 UpdateLocal(bv, NONE, false);
603 sel_pos_start = sel_pos_end = cursor.pos();
604 sel_cell_start = sel_cell_end = actcell;
606 bool const inset_hit = InsetHit(bv, x, y);
608 if ((ocell == actcell) && the_locking_inset && inset_hit) {
609 cursor.pos(0); // always before the inset!
611 the_locking_inset->InsetButtonPress(bv,
612 x - inset_x, y - inset_y, button);
614 } else if (the_locking_inset) {
615 the_locking_inset->InsetUnlock(bv);
617 the_locking_inset = 0;
618 if (inset_hit && bv->theLockingInset()) {
619 if (ActivateCellInset(bv, x, y, button))
620 the_locking_inset->InsetButtonPress(bv, x - inset_x,
621 y - inset_y, button);
628 void InsetTabular::InsetButtonRelease(BufferView * bv,
629 int x, int y, int button)
632 if (the_locking_inset) {
634 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
635 i->InsetButtonRelease(bv, x, y, button);
639 bv->owner()->getDialogs()->showTabular(this);
642 if (the_locking_inset) {
643 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
646 no_selection = false;
650 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
652 if (the_locking_inset) {
653 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
654 y - inset_y, button);
659 LyXParagraph::size_type const old_pos = sel_pos_end;
660 int const old_cell = actcell;
663 sel_pos_end = cursor.pos();
664 sel_cell_end = actcell;
665 if ((sel_cell_end != old_cell) || (old_pos != sel_pos_end))
666 UpdateLocal(bv, SELECTION, false);
669 no_selection = false;
673 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
675 if (the_locking_inset) {
676 the_locking_inset->InsetKeyPress(xke);
682 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
685 UpdatableInset::RESULT
688 no_selection = false;
689 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
690 || (result == DISPATCHED_NOUPDATE)) {
696 if ((action < 0) && arg.empty())
699 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
700 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
702 if (the_locking_inset) {
703 result=the_locking_inset->LocalDispatch(bv, action, arg);
704 if (result == DISPATCHED_NOUPDATE)
706 else if (result == DISPATCHED) {
707 the_locking_inset->ToggleInsetCursor(bv);
708 UpdateLocal(bv, CELL, false);
709 the_locking_inset->ToggleInsetCursor(bv);
711 } else if (result == FINISHED) {
712 if ((action == LFUN_RIGHT) || (action == -1)) {
713 cursor.pos(inset_pos + 1);
716 sel_pos_start = sel_pos_end = cursor.pos();
717 sel_cell_start = sel_cell_end = actcell;
725 bool hs = hasSelection();
729 // --- Cursor Movements ---------------------------------------------
731 if (tabular->IsLastCellInRow(actcell) && !cellstart(cursor.pos()))
733 moveRight(bv, false);
735 if (!cellstart(cursor.pos())) {
736 sel_pos_end = 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;
744 sel_pos_end = cursor.pos();
745 sel_cell_end = actcell;
747 UpdateLocal(bv, SELECTION, false);
750 result = moveRight(bv);
751 sel_pos_start = sel_pos_end = cursor.pos();
752 sel_cell_start = sel_cell_end = actcell;
754 UpdateLocal(bv, SELECTION, false);
757 if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos()))
761 if (cellstart(cursor.pos())) {
762 sel_pos_end = cursor.pos();
763 if (tabular->column_of_cell(sel_cell_start) >=
764 tabular->column_of_cell(actcell))
765 sel_cell_end = actcell;
767 sel_cell_end = actcell-1;
770 sel_pos_end = cursor.pos();
771 sel_cell_end = actcell;
773 UpdateLocal(bv, SELECTION, false);
776 result = moveLeft(bv);
777 sel_pos_start = sel_pos_end = cursor.pos();
778 sel_cell_start = sel_cell_end = actcell;
780 UpdateLocal(bv, SELECTION, false);
784 int const ocell = actcell;
786 sel_pos_end = cursor.pos();
787 if ((ocell == sel_cell_end) ||
788 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
789 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
791 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
792 UpdateLocal(bv, SELECTION, false);
796 result = moveDown(bv);
797 sel_pos_start = sel_pos_end = cursor.pos();
798 sel_cell_start = sel_cell_end = actcell;
800 UpdateLocal(bv, SELECTION, false);
804 int const ocell = actcell;
806 sel_pos_end = cursor.pos();
807 if ((ocell == sel_cell_end) ||
808 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
809 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
811 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
812 UpdateLocal(bv, SELECTION, false);
817 sel_pos_start = sel_pos_end = cursor.pos();
818 sel_cell_start = sel_cell_end = actcell;
820 UpdateLocal(bv, SELECTION, false);
832 if (the_locking_inset) {
833 UnlockInsetInInset(bv, the_locking_inset);
834 the_locking_inset = 0;
836 if (action == LFUN_TAB)
840 sel_pos_start = sel_pos_end = cursor.pos();
841 sel_cell_start = sel_cell_end = actcell;
843 UpdateLocal(bv, SELECTION, false);
845 case LFUN_LAYOUT_TABULAR:
847 bv->owner()->getDialogs()->showTabular(this);
850 case LFUN_TABULAR_FEATURE:
851 if (!TabularFeatures(bv, arg))
852 result = UNDISPATCHED;
855 if (!copySelection(bv))
857 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
859 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
860 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
862 bv->text->cursor.par()->previous,
863 bv->text->cursor.par()->next
867 UpdateLocal(bv, INIT, true);
872 bv->text->FinishUndo();
876 if (!hasPasteBuffer())
878 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
880 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
881 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
883 bv->text->cursor.par()->previous,
884 bv->text->cursor.par()->next
888 UpdateLocal(bv, INIT, true);
891 // we try to activate the actual inset and put this event down to
892 // the insets dispatch function.
893 result = UNDISPATCHED;
894 if (the_locking_inset)
896 if (ActivateCellInset(bv, 0, 0, 0, !cellstart(cursor.pos()))) {
897 result=the_locking_inset->LocalDispatch(bv, action, arg);
898 if (result == DISPATCHED_NOUPDATE)
900 else if (result == DISPATCHED) {
901 the_locking_inset->ToggleInsetCursor(bv);
902 UpdateLocal(bv, CELL, false);
903 the_locking_inset->ToggleInsetCursor(bv);
906 result = UNDISPATCHED;
911 if (result!=FINISHED) {
912 if (!the_locking_inset) {
916 bv->unlockInset(this);
921 int InsetTabular::Latex(Buffer const * buf, ostream & os,
922 bool fragile, bool fp) const
924 return tabular->Latex(buf, os, fragile, fp);
928 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
930 // This should be changed to a real ascii export
931 return tabular->Ascii(buf, os);
935 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
941 int InsetTabular::DocBook(Buffer const * buf, ostream & os) const
943 return tabular->DocBook(buf,os);
947 void InsetTabular::Validate(LaTeXFeatures & features) const
949 tabular->Validate(features);
953 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
954 LyXFont const & font,
960 bool changed = false;
962 for(int i = 0; i < tabular->rows(); ++i) {
963 maxAsc = maxDesc = 0;
964 for(int j= 0; j < tabular->columns(); ++j) {
965 if (tabular->IsPartOfMultiColumn(i,j))
968 inset = tabular->GetCellInset(cell);
970 inset->update(bv, font, false);
971 maxAsc = max(maxAsc, inset->ascent(bv, font));
972 maxDesc = max(maxDesc, inset->descent(bv, font));
973 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
975 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
976 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
982 void InsetTabular::GetCursorPos(BufferView *,
983 int & x, int & y) const
985 x = cursor.x() - top_x;
990 void InsetTabular::ToggleInsetCursor(BufferView * bv)
992 if (the_locking_inset) {
993 the_locking_inset->ToggleInsetCursor(bv);
997 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
999 int const asc = lyxfont::maxAscent(font);
1000 int const desc = lyxfont::maxDescent(font);
1003 bv->hideLockedInsetCursor();
1005 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1006 cursor_visible = !cursor_visible;
1010 void InsetTabular::ShowInsetCursor(BufferView * bv, bool show)
1012 if (!cursor_visible) {
1013 LyXFont font; // = GetFont(par, cursor.pos);
1015 int const asc = lyxfont::maxAscent(font);
1016 int const desc = lyxfont::maxDescent(font);
1017 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1019 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1020 cursor_visible = true;
1025 void InsetTabular::HideInsetCursor(BufferView * bv)
1027 if (cursor_visible) {
1028 bv->hideLockedInsetCursor();
1029 cursor_visible = false;
1031 // if (cursor_visible)
1032 // ToggleInsetCursor(bv);
1036 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1041 actcell = actrow = actcol = 0;
1042 int ly = tabular->GetDescentOfRow(actrow);
1044 // first search the right row
1045 while((ly < y) && (actrow < tabular->rows())) {
1046 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1047 tabular->GetAscentOfRow(actrow + 1) +
1048 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1051 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1053 actcell = tabular->GetCellNumber(actrow, actcol);
1055 // now search the right column
1056 int lx = tabular->GetWidthOfColumn(actcell) -
1057 tabular->GetAdditionalWidth(actcell);
1058 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1060 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
1061 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1062 tabular->GetAdditionalWidth(actcell - 1));
1064 // Jürgen, you should check that this is correct. (Lgb)
1065 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1066 lx += tabular->GetWidthOfColumn(actcell + 1)
1067 + tabular->GetAdditionalWidth(actcell);
1073 if ((lx - (tabular->GetWidthOfColumn(actcell) / 2)) < x) {
1074 cursor.x(lx + top_x - 2);
1077 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1083 int InsetTabular::getCellXPos(int cell) const
1087 for(; !tabular->IsFirstCellInRow(c); --c)
1089 int lx = tabular->GetWidthOfColumn(cell);
1090 for(; c < cell; ++c) {
1091 lx += tabular->GetWidthOfColumn(c);
1093 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1097 void InsetTabular::resetPos(BufferView * bv) const
1101 actcol = tabular->column_of_cell(actcell);
1106 for(; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1107 if (tabular->IsLastCellInRow(cell)) {
1108 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1109 tabular->GetAscentOfRow(actrow + 1) +
1110 tabular->GetAdditionalHeight(cell + 1));
1114 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1115 cursor.x(getCellXPos(actcell) + offset);
1116 if (((cursor.x() - offset) > 20) &&
1117 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1118 (bv->workWidth()-20)))
1120 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1121 UpdateLocal(bv, FULL, false);
1122 } else if ((cursor.x() - offset) < 20) {
1123 scroll(bv, 20 - cursor.x() + offset);
1124 UpdateLocal(bv, FULL, false);
1125 } else if (!cellstart(cursor.pos())) {
1126 LyXFont font(LyXFont::ALL_SANE);
1127 cursor.x(cursor.x() + tabular->GetCellInset(actcell)->width(bv,font) +
1128 tabular->GetBeginningOfTextInCell(actcell));
1130 if ((!the_locking_inset ||
1131 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1132 (actcell != oldcell)) {
1133 InsetTabular * inset = const_cast<InsetTabular *>(this);
1134 bv->owner()->getDialogs()->updateTabular(inset);
1140 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1142 if (!cellstart(cursor.pos())) {
1143 if (tabular->IsLastCell(actcell))
1148 if (ActivateCellInset(bv))
1150 } else { // before the inset
1154 return DISPATCHED_NOUPDATE;
1158 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1160 if (cellstart(cursor.pos()) && !actcell)
1162 if (cellstart(cursor.pos())) {
1165 } else if (lock) { // behind the inset
1167 if (ActivateCellInset(bv, 0, 0, 0, true))
1173 return DISPATCHED_NOUPDATE;
1177 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv)
1179 int const ocell = actcell;
1180 actcell = tabular->GetCellAbove(actcell);
1181 if (actcell == ocell) // we moved out of the inset
1184 return DISPATCHED_NOUPDATE;
1188 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv)
1190 int const ocell = actcell;
1191 actcell = tabular->GetCellBelow(actcell);
1192 if (actcell == ocell) // we moved out of the inset
1195 return DISPATCHED_NOUPDATE;
1199 bool InsetTabular::moveNextCell(BufferView * bv)
1201 if (tabular->IsLastCell(actcell))
1209 bool InsetTabular::movePrevCell(BufferView * bv)
1211 if (!actcell) // first cell
1219 bool InsetTabular::Delete()
1225 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1227 if (the_locking_inset)
1228 the_locking_inset->SetFont(bv, font, tall);
1232 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1234 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1237 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1238 string const tmp = tabularFeatures[i].feature;
1240 if (tmp == what.substr(0, tmp.length())) {
1241 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1242 //tabularFeatures[i].feature.length())) {
1243 action = tabularFeatures[i].action;
1247 if (action == LyXTabular::LAST_ACTION)
1251 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1252 TabularFeatures(bv, action, val);
1257 void InsetTabular::TabularFeatures(BufferView * bv,
1258 LyXTabular::Feature feature,
1259 string const & value)
1268 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1269 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1274 case LyXTabular::M_ALIGN_LEFT:
1275 case LyXTabular::ALIGN_LEFT:
1276 setAlign=LYX_ALIGN_LEFT;
1278 case LyXTabular::M_ALIGN_RIGHT:
1279 case LyXTabular::ALIGN_RIGHT:
1280 setAlign=LYX_ALIGN_RIGHT;
1282 case LyXTabular::M_ALIGN_CENTER:
1283 case LyXTabular::ALIGN_CENTER:
1284 setAlign=LYX_ALIGN_CENTER;
1286 case LyXTabular::M_VALIGN_TOP:
1287 case LyXTabular::VALIGN_TOP:
1288 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1290 case LyXTabular::M_VALIGN_BOTTOM:
1291 case LyXTabular::VALIGN_BOTTOM:
1292 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1294 case LyXTabular::M_VALIGN_CENTER:
1295 case LyXTabular::VALIGN_CENTER:
1296 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1301 if (hasSelection()) {
1302 sel_col_start = tabular->column_of_cell(sel_cell_start);
1303 sel_col_end = tabular->column_of_cell(sel_cell_end);
1304 if (sel_col_start > sel_col_end) {
1305 sel_col_end = sel_col_start;
1306 sel_col_start = tabular->column_of_cell(sel_cell_end);
1308 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1311 sel_row_start = tabular->row_of_cell(sel_cell_start);
1312 sel_row_end = tabular->row_of_cell(sel_cell_end);
1313 if (sel_row_start > sel_row_end) {
1314 //int tmp = sel_row_start;
1315 //sel_row_start = sel_row_end;
1316 //sel_row_end = tmp;
1317 swap(sel_row_start, sel_row_end);
1320 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1321 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1323 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1325 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1326 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1328 bv->text->cursor.par()->previous,
1329 bv->text->cursor.par()->next
1333 int row = tabular->row_of_cell(actcell);
1334 int column = tabular->column_of_cell(actcell);
1338 case LyXTabular::SET_PWIDTH:
1340 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1341 tabular->SetColumnPWidth(actcell,value);
1343 for (int i=0; i < tabular->rows(); ++i) {
1344 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1347 UpdateLocal(bv, INIT, true);
1351 case LyXTabular::SET_MPWIDTH:
1353 bool const update = (tabular->GetPWidth(actcell) != value);
1354 tabular->SetMColumnPWidth(actcell,value);
1356 for (int i=0; i < tabular->rows(); ++i) {
1357 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1360 UpdateLocal(bv, INIT, true);
1364 case LyXTabular::SET_SPECIAL_COLUMN:
1365 case LyXTabular::SET_SPECIAL_MULTI:
1366 tabular->SetAlignSpecial(actcell,value,feature);
1368 case LyXTabular::APPEND_ROW:
1369 // append the row into the tabular
1370 UnlockInsetInInset(bv, the_locking_inset);
1371 tabular->AppendRow(actcell);
1372 UpdateLocal(bv, INIT, true);
1374 case LyXTabular::APPEND_COLUMN:
1375 // append the column into the tabular
1376 tabular->AppendColumn(actcell);
1377 actcell = tabular->GetCellNumber(row, column);
1378 UpdateLocal(bv, INIT, true);
1380 case LyXTabular::DELETE_ROW:
1381 tabular->DeleteRow(tabular->row_of_cell(actcell));
1382 if ((row+1) > tabular->rows())
1384 actcell = tabular->GetCellNumber(row, column);
1385 UpdateLocal(bv, INIT, true);
1387 case LyXTabular::DELETE_COLUMN:
1388 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1389 if ((column+1) > tabular->columns())
1391 actcell = tabular->GetCellNumber(row, column);
1392 UpdateLocal(bv, INIT, true);
1394 case LyXTabular::M_TOGGLE_LINE_TOP:
1396 case LyXTabular::TOGGLE_LINE_TOP:
1397 lineSet = !tabular->TopLine(actcell, flag);
1398 for(i=sel_row_start; i<=sel_row_end; ++i)
1399 for(j=sel_col_start; j<=sel_col_end; ++j)
1400 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1401 UpdateLocal(bv, INIT, true);
1404 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1406 case LyXTabular::TOGGLE_LINE_BOTTOM:
1407 lineSet = !tabular->BottomLine(actcell, flag);
1408 for(i=sel_row_start; i<=sel_row_end; ++i)
1409 for(j=sel_col_start; j<=sel_col_end; ++j)
1410 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1412 UpdateLocal(bv, INIT, true);
1415 case LyXTabular::M_TOGGLE_LINE_LEFT:
1417 case LyXTabular::TOGGLE_LINE_LEFT:
1418 lineSet = !tabular->LeftLine(actcell, flag);
1419 for(i=sel_row_start; i<=sel_row_end; ++i)
1420 for(j=sel_col_start; j<=sel_col_end; ++j)
1421 tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1423 UpdateLocal(bv, INIT, true);
1426 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1428 case LyXTabular::TOGGLE_LINE_RIGHT:
1429 lineSet = !tabular->RightLine(actcell, flag);
1430 for(i=sel_row_start; i<=sel_row_end; ++i)
1431 for(j=sel_col_start; j<=sel_col_end; ++j)
1432 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1434 UpdateLocal(bv, INIT, true);
1436 case LyXTabular::M_ALIGN_LEFT:
1437 case LyXTabular::M_ALIGN_RIGHT:
1438 case LyXTabular::M_ALIGN_CENTER:
1440 case LyXTabular::ALIGN_LEFT:
1441 case LyXTabular::ALIGN_RIGHT:
1442 case LyXTabular::ALIGN_CENTER:
1443 for(i = sel_row_start; i <= sel_row_end; ++i)
1444 for(j = sel_col_start; j <= sel_col_end; ++j)
1445 tabular->SetAlignment(tabular->GetCellNumber(i, j), setAlign,
1448 UpdateLocal(bv, INIT, true);
1450 UpdateLocal(bv, CELL, true);
1452 case LyXTabular::M_VALIGN_TOP:
1453 case LyXTabular::M_VALIGN_BOTTOM:
1454 case LyXTabular::M_VALIGN_CENTER:
1456 case LyXTabular::VALIGN_TOP:
1457 case LyXTabular::VALIGN_BOTTOM:
1458 case LyXTabular::VALIGN_CENTER:
1459 for(i = sel_row_start; i <= sel_row_end; ++i)
1460 for(j = sel_col_start; j <= sel_col_end; ++j)
1461 tabular->SetVAlignment(tabular->GetCellNumber(i, j),
1464 UpdateLocal(bv, INIT, true);
1466 UpdateLocal(bv, CELL, true);
1468 case LyXTabular::MULTICOLUMN:
1470 if (sel_row_start != sel_row_end) {
1471 WriteAlert(_("Impossible Operation!"),
1472 _("Multicolumns can only be horizontally."),
1476 // just multicol for one Single Cell
1477 if (!hasSelection()) {
1478 // check wether we are completly in a multicol
1479 if (tabular->IsMultiColumn(actcell)) {
1480 tabular->UnsetMultiColumn(actcell);
1481 UpdateLocal(bv, INIT, true);
1483 tabular->SetMultiColumn(actcell, 1);
1484 UpdateLocal(bv, CELL, true);
1488 // we have a selection so this means we just add all this
1489 // cells to form a multicolumn cell
1493 if (sel_cell_start > sel_cell_end) {
1494 s_start = sel_cell_end;
1495 s_end = sel_cell_start;
1497 s_start = sel_cell_start;
1498 s_end = sel_cell_end;
1500 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1503 sel_cell_end = sel_cell_start;
1504 sel_pos_end = sel_pos_start;
1505 UpdateLocal(bv, INIT, true);
1508 case LyXTabular::SET_ALL_LINES:
1510 case LyXTabular::UNSET_ALL_LINES:
1511 for(i=sel_row_start; i<=sel_row_end; ++i)
1512 for(j=sel_col_start; j<=sel_col_end; ++j)
1513 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1514 UpdateLocal(bv, INIT, true);
1516 case LyXTabular::SET_LONGTABULAR:
1517 tabular->SetLongTabular(true);
1518 UpdateLocal(bv, INIT, true); // because this toggles displayed
1520 case LyXTabular::UNSET_LONGTABULAR:
1521 tabular->SetLongTabular(false);
1522 UpdateLocal(bv, INIT, true); // because this toggles displayed
1524 case LyXTabular::SET_ROTATE_TABULAR:
1525 tabular->SetRotateTabular(true);
1527 case LyXTabular::UNSET_ROTATE_TABULAR:
1528 tabular->SetRotateTabular(false);
1530 case LyXTabular::SET_ROTATE_CELL:
1531 for(i=sel_row_start; i<=sel_row_end; ++i)
1532 for(j=sel_col_start; j<=sel_col_end; ++j)
1533 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1535 case LyXTabular::UNSET_ROTATE_CELL:
1536 for(i = sel_row_start; i <= sel_row_end; ++i)
1537 for(j = sel_col_start; j <= sel_col_end; ++j)
1538 tabular->SetRotateCell(tabular->GetCellNumber(i, j), false);
1540 case LyXTabular::SET_USEBOX:
1542 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1543 if (val == tabular->GetUsebox(actcell))
1544 val = LyXTabular::BOX_NONE;
1545 for(i = sel_row_start; i <= sel_row_end; ++i)
1546 for(j = sel_col_start; j <= sel_col_end; ++j)
1547 tabular->SetUsebox(tabular->GetCellNumber(i, j), val);
1550 case LyXTabular::SET_LTFIRSTHEAD:
1551 tabular->SetLTHead(actcell, true);
1553 case LyXTabular::SET_LTHEAD:
1554 tabular->SetLTHead(actcell, false);
1556 case LyXTabular::SET_LTFOOT:
1557 tabular->SetLTFoot(actcell, false);
1559 case LyXTabular::SET_LTLASTFOOT:
1560 tabular->SetLTFoot(actcell, true);
1562 case LyXTabular::SET_LTNEWPAGE:
1563 what = !tabular->GetLTNewPage(actcell);
1564 tabular->SetLTNewPage(actcell, what);
1566 // dummy stuff just to avoid warnings
1567 case LyXTabular::LAST_ACTION:
1573 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1576 // the cursor.pos has to be before the inset so if it isn't now just
1577 // reset the curor pos first!
1578 if (!cellstart(cursor.pos())) {
1582 UpdatableInset * inset =
1583 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1584 LyXFont font(LyXFont::ALL_SANE);
1586 x = inset->x() + inset->width(bv, font);
1587 y = inset->descent(bv, font);
1589 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1590 inset_y = cursor.y();
1591 inset->Edit(bv, x, y - inset_y, button);
1592 if (!the_locking_inset)
1594 UpdateLocal(bv, CELL, false);
1595 return (the_locking_inset != 0);
1599 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1601 InsetText * inset = tabular->GetCellInset(actcell);
1604 if (!cellstart(cursor.pos())) {
1605 return (((x + top_x) < cursor.x()) &&
1606 ((x + top_x) > (cursor.x() - inset->width(bv,
1607 LyXFont(LyXFont::ALL_SANE)))));
1609 int x2 = cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1610 return ((x1 > x2) &&
1611 (x1 < (x2 + inset->width(bv, LyXFont(LyXFont::ALL_SANE)))));
1616 // This returns paperWidth() if the cell-width is unlimited or the width
1617 // in pixels if we have a pwidth for this cell.
1618 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1620 string const s = tabular->GetPWidth(cell);
1624 return VSpace(s).inPixels(0, 0);
1628 int InsetTabular::getMaxWidth(Painter & pain,
1629 UpdatableInset const * inset) const
1631 int const n = tabular->GetNumberOfCells();
1633 for(; cell < n; ++cell) {
1634 if (tabular->GetCellInset(cell) == inset)
1639 int w = GetMaxWidthOfCell(pain, cell);
1641 // because the inset then subtracts it's top_x and owner->x()
1642 w += (inset->x() - top_x);
1647 void InsetTabular::resizeLyXText(BufferView *) const
1653 LyXText * InsetTabular::getLyXText(BufferView * bv) const
1655 if (the_locking_inset)
1656 return the_locking_inset->getLyXText(bv);
1657 return Inset::getLyXText(bv);
1661 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1663 if (the_locking_inset) {
1664 InsetTabular * i = static_cast<InsetTabular *>
1665 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1667 i->OpenLayoutDialog(bv);
1671 bv->owner()->getDialogs()->showTabular(const_cast<InsetTabular *>(this));
1675 // functions returns:
1679 // 3 ... toggled off
1681 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1683 int action = LyXTabular::LAST_ACTION;
1684 LyXFunc::func_status status = LyXFunc::OK;
1687 for(; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1688 string const tmp = tabularFeatures[i].feature;
1689 if (tmp == what.substr(0, tmp.length())) {
1690 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1691 // tabularFeatures[i].feature.length())) {
1692 action = tabularFeatures[i].action;
1696 if (action == LyXTabular::LAST_ACTION)
1697 return LyXFunc::Unknown;
1699 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1701 int sel_row_start, sel_row_end;
1705 if (hasSelection()) {
1706 sel_row_start = tabular->row_of_cell(sel_cell_start);
1707 sel_row_end = tabular->row_of_cell(sel_cell_end);
1708 if (sel_row_start > sel_row_end) {
1709 //int tmp = sel_row_start;
1710 //sel_row_start = sel_row_end;
1711 //sel_row_end = tmp;
1712 swap(sel_row_start, sel_row_end);
1715 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1719 case LyXTabular::SET_PWIDTH:
1720 case LyXTabular::SET_MPWIDTH:
1721 case LyXTabular::SET_SPECIAL_COLUMN:
1722 case LyXTabular::SET_SPECIAL_MULTI:
1723 status |= LyXFunc::Disabled;
1726 case LyXTabular::APPEND_ROW:
1727 case LyXTabular::APPEND_COLUMN:
1728 case LyXTabular::DELETE_ROW:
1729 case LyXTabular::DELETE_COLUMN:
1730 case LyXTabular::SET_ALL_LINES:
1731 case LyXTabular::UNSET_ALL_LINES:
1732 status |= LyXFunc::OK;
1735 case LyXTabular::MULTICOLUMN:
1736 if (tabular->IsMultiColumn(actcell))
1737 status |= LyXFunc::ToggleOn;
1739 status |= LyXFunc::ToggleOff;
1741 case LyXTabular::M_TOGGLE_LINE_TOP:
1743 case LyXTabular::TOGGLE_LINE_TOP:
1744 if (tabular->TopLine(actcell, flag))
1745 status |= LyXFunc::ToggleOn;
1747 status |= LyXFunc::ToggleOff;
1749 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1751 case LyXTabular::TOGGLE_LINE_BOTTOM:
1752 if (tabular->BottomLine(actcell, flag))
1753 status |= LyXFunc::ToggleOn;
1755 status |= LyXFunc::ToggleOff;
1757 case LyXTabular::M_TOGGLE_LINE_LEFT:
1759 case LyXTabular::TOGGLE_LINE_LEFT:
1760 if (tabular->LeftLine(actcell, flag))
1761 status |= LyXFunc::ToggleOn;
1763 status |= LyXFunc::ToggleOff;
1765 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1767 case LyXTabular::TOGGLE_LINE_RIGHT:
1768 if (tabular->RightLine(actcell, flag))
1769 status |= LyXFunc::ToggleOn;
1771 status |= LyXFunc::ToggleOff;
1773 case LyXTabular::M_ALIGN_LEFT:
1775 case LyXTabular::ALIGN_LEFT:
1776 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1777 status |= LyXFunc::ToggleOn;
1779 status |= LyXFunc::ToggleOff;
1781 case LyXTabular::M_ALIGN_RIGHT:
1783 case LyXTabular::ALIGN_RIGHT:
1784 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1785 status |= LyXFunc::ToggleOn;
1787 status |= LyXFunc::ToggleOff;
1789 case LyXTabular::M_ALIGN_CENTER:
1791 case LyXTabular::ALIGN_CENTER:
1792 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1793 status |= LyXFunc::ToggleOn;
1795 status |= LyXFunc::ToggleOff;
1797 case LyXTabular::M_VALIGN_TOP:
1799 case LyXTabular::VALIGN_TOP:
1800 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1801 status |= LyXFunc::ToggleOn;
1803 status |= LyXFunc::ToggleOff;
1805 case LyXTabular::M_VALIGN_BOTTOM:
1807 case LyXTabular::VALIGN_BOTTOM:
1808 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1809 status |= LyXFunc::ToggleOn;
1811 status |= LyXFunc::ToggleOff;
1813 case LyXTabular::M_VALIGN_CENTER:
1815 case LyXTabular::VALIGN_CENTER:
1816 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1817 status |= LyXFunc::ToggleOn;
1819 status |= LyXFunc::ToggleOff;
1821 case LyXTabular::SET_LONGTABULAR:
1822 if (tabular->IsLongTabular())
1823 status |= LyXFunc::ToggleOn;
1825 status |= LyXFunc::ToggleOff;
1827 case LyXTabular::UNSET_LONGTABULAR:
1828 if (!tabular->IsLongTabular())
1829 status |= LyXFunc::ToggleOn;
1831 status |= LyXFunc::ToggleOff;
1833 case LyXTabular::SET_ROTATE_TABULAR:
1834 if (tabular->GetRotateTabular())
1835 status |= LyXFunc::ToggleOn;
1837 status |= LyXFunc::ToggleOff;
1839 case LyXTabular::UNSET_ROTATE_TABULAR:
1840 if (!tabular->GetRotateTabular())
1841 status |= LyXFunc::ToggleOn;
1843 status |= LyXFunc::ToggleOff;
1845 case LyXTabular::SET_ROTATE_CELL:
1846 if (tabular->GetRotateCell(actcell))
1847 status |= LyXFunc::ToggleOn;
1849 status |= LyXFunc::ToggleOff;
1851 case LyXTabular::UNSET_ROTATE_CELL:
1852 if (!tabular->GetRotateCell(actcell))
1853 status |= LyXFunc::ToggleOn;
1855 status |= LyXFunc::ToggleOff;
1857 case LyXTabular::SET_USEBOX:
1858 if (strToInt(argument) == tabular->GetUsebox(actcell))
1859 status |= LyXFunc::ToggleOn;
1861 status |= LyXFunc::ToggleOff;
1863 case LyXTabular::SET_LTFIRSTHEAD:
1864 if (tabular->GetRowOfLTHead(actcell, dummy))
1865 status |= LyXFunc::ToggleOn;
1867 status |= LyXFunc::ToggleOff;
1869 case LyXTabular::SET_LTHEAD:
1870 if (tabular->GetRowOfLTHead(actcell, dummy))
1871 status |= LyXFunc::ToggleOn;
1873 status |= LyXFunc::ToggleOff;
1875 case LyXTabular::SET_LTFOOT:
1876 if (tabular->GetRowOfLTFoot(actcell, dummy))
1877 status |= LyXFunc::ToggleOn;
1879 status |= LyXFunc::ToggleOff;
1881 case LyXTabular::SET_LTLASTFOOT:
1882 if (tabular->GetRowOfLTFoot(actcell, dummy))
1883 status |= LyXFunc::ToggleOn;
1885 status |= LyXFunc::ToggleOff;
1887 case LyXTabular::SET_LTNEWPAGE:
1888 if (tabular->GetLTNewPage(actcell))
1889 status |= LyXFunc::ToggleOn;
1891 status |= LyXFunc::ToggleOff;
1894 status = LyXFunc::Disabled;
1901 bool InsetTabular::copySelection(BufferView * bv)
1903 if (!hasSelection())
1905 delete paste_tabular;
1907 int sel_col_start, sel_col_end;
1908 int sel_row_start, sel_row_end;
1910 sel_col_start = tabular->column_of_cell(sel_cell_start);
1911 sel_col_end = tabular->column_of_cell(sel_cell_end);
1912 if (sel_col_start > sel_col_end) {
1913 sel_col_start = sel_col_end;
1914 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1916 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1918 int columns = sel_col_end - sel_col_start + 1;
1920 sel_row_start = tabular->row_of_cell(sel_cell_start);
1921 sel_row_end = tabular->row_of_cell(sel_cell_end);
1922 if (sel_row_start > sel_row_end) {
1923 //int tmp tmp = sel_row_start;
1924 //sel_row_start = sel_row_end;
1925 //sel_row_end = tmp;
1926 swap(sel_row_start, sel_row_end);
1928 int rows = sel_row_end - sel_row_start + 1;
1930 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
1932 for(i=0; i < sel_row_start; ++i)
1933 paste_tabular->DeleteRow(0);
1934 while(paste_tabular->rows() > rows)
1935 paste_tabular->DeleteRow(rows);
1936 paste_tabular->SetTopLine(0, true, true);
1937 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
1939 for(i=0; i < sel_col_start; ++i)
1940 paste_tabular->DeleteColumn(0);
1941 while(paste_tabular->columns() > columns)
1942 paste_tabular->DeleteColumn(columns);
1943 paste_tabular->SetLeftLine(0, true, true);
1944 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),true, true);
1947 paste_tabular->Ascii(bv->buffer(), sstr);
1948 bv->stuffClipboard(sstr.str());
1953 bool InsetTabular::pasteSelection(BufferView * bv)
1957 for(int j=0, i=actcell; j<paste_tabular->GetNumberOfCells(); ++j,++i) {
1958 while (paste_tabular->row_of_cell(j) > tabular->row_of_cell(i)-actrow)
1960 if (tabular->GetNumberOfCells() <= i)
1962 while (paste_tabular->row_of_cell(j) < tabular->row_of_cell(i)-actrow)
1964 if (paste_tabular->GetNumberOfCells() <= j)
1966 *(tabular->GetCellInset(i)) = *(paste_tabular->GetCellInset(j));
1967 tabular->GetCellInset(i)->setOwner(this);
1968 tabular->GetCellInset(i)->deleteLyXText(bv);
1974 bool InsetTabular::cutSelection()
1976 if (!hasSelection())
1979 int sel_col_start, sel_col_end;
1980 int sel_row_start, sel_row_end;
1982 sel_col_start = tabular->column_of_cell(sel_cell_start);
1983 sel_col_end = tabular->column_of_cell(sel_cell_end);
1984 if (sel_col_start > sel_col_end) {
1985 sel_col_start = sel_col_end;
1986 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
1988 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1990 sel_row_start = tabular->row_of_cell(sel_cell_start);
1991 sel_row_end = tabular->row_of_cell(sel_cell_end);
1992 if (sel_row_start > sel_row_end) {
1993 //int tmp = sel_row_start;
1994 //sel_row_start = sel_row_end;
1995 //sel_row_end = tmp;
1996 swap(sel_row_start, sel_row_end);
1998 if (sel_cell_start > sel_cell_end) {
1999 //int tmp = sel_cell_start;
2000 //sel_cell_start = sel_cell_end;
2001 //sel_cell_end = tmp;
2002 swap(sel_cell_start, sel_cell_end);
2004 for(int i = sel_row_start; i <= sel_row_end; ++i) {
2005 for(int j = sel_col_start; j <= sel_col_end; ++j) {
2006 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();