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"
40 const int ADD_TO_HEIGHT = 2;
41 const int ADD_TO_TABULAR_WIDTH = 2;
43 static LyXTabular * paste_tabular = 0;
44 bool InsetTabular::hasPasteBuffer() const
46 return (paste_tabular != 0);
57 struct tabular_features {
58 LyXTabular::Feature action;
62 //static tabular_features * tabularFeatures = 0;
64 static tabular_features tabularFeatures[] =
66 { LyXTabular::APPEND_ROW, "append-row" },
67 { LyXTabular::APPEND_COLUMN, "append-column" },
68 { LyXTabular::DELETE_ROW, "delete-row" },
69 { LyXTabular::DELETE_COLUMN, "delete-column" },
70 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
71 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
72 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
73 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
74 { LyXTabular::ALIGN_LEFT, "align-left" },
75 { LyXTabular::ALIGN_RIGHT, "align-right" },
76 { LyXTabular::ALIGN_CENTER, "align-center" },
77 { LyXTabular::VALIGN_TOP, "valign-top" },
78 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
79 { LyXTabular::VALIGN_CENTER, "valign-center" },
80 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
81 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
82 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
83 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
84 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
85 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
86 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
87 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
88 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
89 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
90 { LyXTabular::MULTICOLUMN, "multicolumn" },
91 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
92 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
93 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
94 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
95 { LyXTabular::SET_PWIDTH, "set-pwidth" },
96 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
97 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
98 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
99 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
100 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
101 { LyXTabular::SET_USEBOX, "set-usebox" },
102 { LyXTabular::SET_LTHEAD, "set-lthead" },
103 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
104 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
105 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
106 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
107 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
108 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
109 { LyXTabular::LAST_ACTION, "" }
112 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
119 tabular = new LyXTabular(this, rows,columns);
120 // for now make it always display as display() inset
122 the_locking_inset = 0;
123 locked = no_selection = cursor_visible = false;
126 actrow = actcell = 0;
132 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
135 tabular = new LyXTabular(this, *(tab.tabular));
136 the_locking_inset = 0;
137 locked = no_selection = cursor_visible = false;
140 actrow = actcell = 0;
141 sel_cell_start = sel_cell_end = 0;
146 InsetTabular::~InsetTabular()
153 Inset * InsetTabular::Clone(Buffer const & buf) const
155 InsetTabular * t = new InsetTabular(*this, buf);
157 t->tabular = tabular->Clone(t);
162 void InsetTabular::Write(Buffer const * buf, ostream & os) const
164 os << " Tabular" << endl;
165 tabular->Write(buf, os);
169 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
171 bool old_format = (lex.GetString() == "\\LyXTable");
176 tabular = new LyXTabular(buf, this, lex);
184 token = lex.GetString();
185 while (lex.IsOK() && (token != "\\end_inset")) {
187 token = lex.GetString();
189 if (token != "\\end_inset") {
190 lex.printError("Missing \\end_inset at this point. "
196 int InsetTabular::ascent(BufferView *, LyXFont const &) const
198 return tabular->GetAscentOfRow(0);
202 int InsetTabular::descent(BufferView *, LyXFont const &) const
204 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
208 int InsetTabular::width(BufferView *, LyXFont const &) const
210 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
214 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
215 float & x, bool cleared) const
217 Painter & pain = bv->painter();
221 UpdatableInset::draw(bv, font, baseline, x, cleared);
222 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
223 (top_x != int(x)) || (top_baseline != baseline))) {
224 int h = ascent(bv, font) + descent(bv, font);
225 int tx = display() || !owner() ? 0 : top_x;
226 int w = tx ? width(bv, font) : pain.paperWidth();
227 int ty = baseline - ascent(bv, font);
231 if ((ty + h) > pain.paperHeight())
232 h = pain.paperHeight();
233 if ((top_x + w) > pain.paperWidth())
234 w = pain.paperWidth();
235 pain.fillRectangle(tx, ty, w, h);
240 top_baseline = baseline;
241 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
244 x += ADD_TO_TABULAR_WIDTH;
248 for (i = 0; i < tabular->rows(); ++i) {
250 dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
251 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight();
252 for (j = 0; j < tabular->columns(); ++j) {
253 if (tabular->IsPartOfMultiColumn(i, j))
255 cx = nx + tabular->GetBeginningOfTextInCell(cell);
258 DrawCellSelection(pain, nx, baseline, i, j, cell);
259 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
261 DrawCellLines(pain, nx, baseline, i, cell);
263 nx += tabular->GetWidthOfColumn(cell);
266 baseline += tabular->GetDescentOfRow(i) +
267 tabular->GetAscentOfRow(i + 1) +
268 tabular->GetAdditionalHeight(cell);
270 } else if (need_update == CELL) {
273 if (the_locking_inset) {
274 Inset * inset = tabular->GetCellInset(cell);
275 for (i = 0; (inset != the_locking_inset) && (i < tabular->rows());
278 for (j = 0; (inset != the_locking_inset) && (j < tabular->columns()); ++j)
280 if (tabular->IsPartOfMultiColumn(i, j))
282 nx += tabular->GetWidthOfColumn(cell);
284 inset = tabular->GetCellInset(cell);
286 if (tabular->row_of_cell(cell) > i) {
288 baseline += tabular->GetDescentOfRow(i) +
289 tabular->GetAscentOfRow(i + 1) +
290 tabular->GetAdditionalHeight(cell);
294 for (i = 0; (cell < actcell) && (i < tabular->rows()); ++i) {
295 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
296 if (tabular->IsPartOfMultiColumn(i, j))
298 nx += tabular->GetWidthOfColumn(cell);
301 if (tabular->row_of_cell(cell) > i) {
303 baseline += tabular->GetDescentOfRow(i) +
304 tabular->GetAscentOfRow(i + 1) +
305 tabular->GetAdditionalHeight(cell);
309 i = tabular->row_of_cell(cell);
310 if (the_locking_inset != tabular->GetCellInset(cell)) {
311 lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
314 // LyXText::text_status st = bv->text->status;
317 float cx = nx + tabular->GetBeginningOfTextInCell(cell);
318 bv->text->status = st;
319 if (need_update == CELL) {
320 // clear before the inset
323 baseline - tabular->GetAscentOfRow(i) + 1,
325 tabular->GetAscentOfRow(i) +
326 tabular->GetDescentOfRow(i) - 1);
327 // clear behind the inset
329 int(cx + the_locking_inset->width(bv,font) + 1),
330 baseline - tabular->GetAscentOfRow(i) + 1,
331 tabular->GetWidthOfColumn(cell) -
332 tabular->GetBeginningOfTextInCell(cell) -
333 the_locking_inset->width(bv,font) -
334 tabular->GetAdditionalWidth(cell) - 1,
335 tabular->GetAscentOfRow(i) +
336 tabular->GetDescentOfRow(i) - 1);
338 tabular->GetCellInset(cell)->draw(bv,font,baseline, cx, false);
339 } while(bv->text->status == LyXText::CHANGED_IN_DRAW);
343 cx = dx = nx + tabular->GetBeginningOfTextInCell(cell);
344 tabular->GetCellInset(cell)->draw(bv,font,baseline, dx, false);
345 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
347 // clear only if we didn't have a change
348 if (need_update == CELL) {
349 // clear before the inset
352 baseline - tabular->GetAscentOfRow(i) + 1,
354 tabular->GetAscentOfRow(i) +
355 tabular->GetDescentOfRow(i) - 1);
356 // clear behind the inset
358 int(cx + the_locking_inset->width(bv,font) + 1),
359 baseline - tabular->GetAscentOfRow(i) + 1,
360 tabular->GetWidthOfColumn(cell) -
361 tabular->GetBeginningOfTextInCell(cell) -
362 the_locking_inset->width(bv,font) -
363 tabular->GetAdditionalWidth(cell) - 1,
364 tabular->GetAscentOfRow(i) +
365 tabular->GetDescentOfRow(i) - 1);
369 x -= ADD_TO_TABULAR_WIDTH;
370 x += width(bv, font);
371 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
378 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
379 int row, int cell) const
381 int x2 = x + tabular->GetWidthOfColumn(cell);
384 if (!tabular->TopAlreadyDrawed(cell)) {
385 on_off = !tabular->TopLine(cell);
386 pain.line(x, baseline - tabular->GetAscentOfRow(row),
387 x2, baseline - tabular->GetAscentOfRow(row),
388 on_off ? LColor::tabularonoffline : LColor::tabularline,
389 on_off ? Painter::line_onoffdash : Painter::line_solid);
391 on_off = !tabular->BottomLine(cell);
392 pain.line(x,baseline + tabular->GetDescentOfRow(row),
393 x2, baseline + tabular->GetDescentOfRow(row),
394 on_off ? LColor::tabularonoffline : LColor::tabularline,
395 on_off ? Painter::line_onoffdash : Painter::line_solid);
396 if (!tabular->LeftAlreadyDrawed(cell)) {
397 on_off = !tabular->LeftLine(cell);
398 pain.line(x, baseline - tabular->GetAscentOfRow(row),
399 x, baseline + tabular->GetDescentOfRow(row),
400 on_off ? LColor::tabularonoffline : LColor::tabularline,
401 on_off ? Painter::line_onoffdash : Painter::line_solid);
403 on_off = !tabular->RightLine(cell);
404 pain.line(x2 - tabular->GetAdditionalWidth(cell),
405 baseline - tabular->GetAscentOfRow(row),
406 x2 - tabular->GetAdditionalWidth(cell),
407 baseline + tabular->GetDescentOfRow(row),
408 on_off ? LColor::tabularonoffline : LColor::tabularline,
409 on_off ? Painter::line_onoffdash : Painter::line_solid);
413 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
414 int row, int column, int cell) const
416 int cs = tabular->column_of_cell(sel_cell_start);
417 int ce = tabular->column_of_cell(sel_cell_end);
420 cs = tabular->column_of_cell(sel_cell_end);
422 ce = tabular->right_column_of_cell(sel_cell_end);
425 int rs = tabular->row_of_cell(sel_cell_start);
426 int re = tabular->row_of_cell(sel_cell_end);
427 if (rs > re) swap(rs, re);
429 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
430 int w = tabular->GetWidthOfColumn(cell);
431 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
432 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
433 w, h, LColor::selection);
438 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
442 calculate_dimensions_of_cells(bv, font, true);
444 owner()->update(bv, font, true);
447 if (the_locking_inset) {
448 the_locking_inset->update(bv, font, reinit);
450 // inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
451 // inset_y = cursor.y();
453 switch (need_update) {
457 if (calculate_dimensions_of_cells(bv, font, false))
469 string const InsetTabular::EditMessage() const
471 return _("Opened Tabular Inset");
475 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
477 UpdatableInset::Edit(bv, x, y, button);
479 if (!bv->lockInset(this)) {
480 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
484 the_locking_inset = 0;
488 sel_cell_start = sel_cell_end = actcell;
489 bv->text->FinishUndo();
490 if (InsetHit(bv, x, y) && (button != 3)) {
491 ActivateCellInsetAbs(bv, x, y, button);
493 // UpdateLocal(bv, NONE, false);
494 // bv->getOwner()->getPopups().updateFormTabular();
498 void InsetTabular::InsetUnlock(BufferView * bv)
500 if (the_locking_inset) {
501 the_locking_inset->InsetUnlock(bv);
502 the_locking_inset = 0;
505 no_selection = false;
508 if (scroll() || hasSelection()) {
512 sel_cell_start = sel_cell_end = 0;
514 UpdateLocal(bv, FULL, false);
519 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
520 bool mark_dirty) const
522 if (need_update < what) // only set this if it has greater update
524 if ((what == INIT) && hasSelection())
527 if (need_update != NONE) {
528 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
529 if (locked) // && (what != NONE))
535 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
537 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
541 if (inset == tabular->GetCellInset(actcell)) {
542 lyxerr[Debug::INSETS] << "OK" << endl;
543 the_locking_inset = tabular->GetCellInset(actcell);
545 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
546 inset_y = cursor.y();
548 } else if (the_locking_inset && (the_locking_inset == inset)) {
549 lyxerr[Debug::INSETS] << "OK" << endl;
551 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
552 inset_y = cursor.y();
553 } else if (the_locking_inset) {
554 lyxerr[Debug::INSETS] << "MAYBE" << endl;
555 return the_locking_inset->LockInsetInInset(bv, inset);
557 lyxerr[Debug::INSETS] << "NOT OK" << endl;
562 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
565 if (!the_locking_inset)
567 if (the_locking_inset == inset) {
568 the_locking_inset->InsetUnlock(bv);
569 the_locking_inset = 0;
570 ShowInsetCursor(bv, false);
571 UpdateLocal(bv, CELL, false);
574 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
575 if (inset->LyxCode() == TABULAR_CODE &&
576 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
578 bv->owner()->getDialogs()->updateTabular(this);
587 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
589 if (!the_locking_inset)
591 if (the_locking_inset != inset) {
592 if (!the_locking_inset->UpdateInsetInInset(bv, inset))
595 UpdateLocal(bv, CELL, false);
600 unsigned int InsetTabular::InsetInInsetY()
602 if (!the_locking_inset)
605 return (inset_y + the_locking_inset->InsetInInsetY());
609 UpdatableInset * InsetTabular::GetLockingInset()
611 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
615 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
619 if (the_locking_inset)
620 return the_locking_inset->GetFirstLockingInsetOfType(c);
625 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
627 if (the_locking_inset)
628 return the_locking_inset->InsertInset(bv, inset);
633 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
635 if (hasSelection() && (button == 3))
638 if (hasSelection()) {
640 UpdateLocal(bv, SELECTION, false);
643 no_selection = false;
645 int const ocell = actcell;
646 int const orow = actrow;
651 UpdateLocal(bv, NONE, false);
652 sel_cell_start = sel_cell_end = actcell;
654 if ((ocell != actcell) && the_locking_inset) {
655 the_locking_inset->InsetUnlock(bv);
656 the_locking_inset = 0;
662 bool const inset_hit = InsetHit(bv, x, y);
664 if ((ocell == actcell) && the_locking_inset && inset_hit) {
666 the_locking_inset->InsetButtonPress(bv,
667 x - inset_x, y - inset_y, button);
669 } else if (the_locking_inset) {
670 the_locking_inset->InsetUnlock(bv);
672 the_locking_inset = 0;
674 LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph");
677 if (inset_hit && bv->theLockingInset()) {
678 if (ActivateCellInsetAbs(bv, x, y, button))
679 the_locking_inset->InsetButtonPress(bv, x - inset_x,
680 y - inset_y, button);
687 void InsetTabular::InsetButtonRelease(BufferView * bv,
688 int x, int y, int button)
691 if (the_locking_inset) {
693 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
694 i->InsetButtonRelease(bv, x, y, button);
698 bv->owner()->getDialogs()->showTabular(this);
701 if (the_locking_inset) {
702 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
705 no_selection = false;
709 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
711 if (the_locking_inset) {
712 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
713 y - inset_y, button);
718 int const old_cell = actcell;
721 sel_cell_end = actcell;
722 if (sel_cell_end != old_cell)
723 UpdateLocal(bv, SELECTION, false);
726 no_selection = false;
730 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
732 if (the_locking_inset) {
733 the_locking_inset->InsetKeyPress(xke);
739 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
742 // We need to save the value of the_locking_inset as the call to
743 // the_locking_inset->LocalDispatch might unlock it.
744 old_locking_inset = the_locking_inset;
745 no_selection = false;
746 UpdatableInset::RESULT result =
747 UpdatableInset::LocalDispatch(bv, action, arg);
748 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
753 if ((action < 0) && arg.empty())
756 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
757 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
759 if (the_locking_inset) {
760 result=the_locking_inset->LocalDispatch(bv, action, arg);
761 if (result == DISPATCHED_NOUPDATE)
763 else if (result == DISPATCHED) {
764 the_locking_inset->ToggleInsetCursor(bv);
765 UpdateLocal(bv, CELL, false);
766 the_locking_inset->ToggleInsetCursor(bv);
768 } else if (result == FINISHED) {
772 bool hs = hasSelection();
776 // --- Cursor Movements ---------------------------------------------
778 if (tabular->IsLastCellInRow(actcell))
780 moveRight(bv, false);
781 sel_cell_end = actcell;
782 UpdateLocal(bv, SELECTION, false);
785 result = moveRight(bv);
786 sel_cell_start = sel_cell_end = actcell;
788 UpdateLocal(bv, SELECTION, false);
791 if (tabular->IsFirstCellInRow(actcell))
794 sel_cell_end = actcell;
795 UpdateLocal(bv, SELECTION, false);
798 result = moveLeft(bv);
799 sel_cell_start = sel_cell_end = actcell;
801 UpdateLocal(bv, SELECTION, false);
805 int const ocell = actcell;
807 if ((ocell == sel_cell_end) ||
808 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
809 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
811 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
812 UpdateLocal(bv, SELECTION, false);
816 result = moveDown(bv, old_locking_inset != 0);
817 sel_cell_start = sel_cell_end = actcell;
819 UpdateLocal(bv, SELECTION, false);
823 int const ocell = actcell;
825 if ((ocell == sel_cell_end) ||
826 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
827 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
829 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
830 UpdateLocal(bv, SELECTION, false);
834 result = moveUp(bv, old_locking_inset != 0);
835 sel_cell_start = sel_cell_end = actcell;
837 UpdateLocal(bv, SELECTION, false);
850 if (the_locking_inset) {
851 UnlockInsetInInset(bv, the_locking_inset);
852 the_locking_inset = 0;
854 if (action == LFUN_TAB)
855 moveNextCell(bv, old_locking_inset != 0);
857 movePrevCell(bv, old_locking_inset != 0);
858 sel_cell_start = sel_cell_end = actcell;
860 UpdateLocal(bv, SELECTION, false);
863 case LFUN_LAYOUT_TABULAR:
865 bv->owner()->getDialogs()->showTabular(this);
868 case LFUN_TABULAR_FEATURE:
869 if (!TabularFeatures(bv, arg))
870 result = UNDISPATCHED;
873 if (!copySelection(bv))
875 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
877 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
878 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
880 bv->text->cursor.par()->previous,
881 bv->text->cursor.par()->next
885 UpdateLocal(bv, INIT, true);
890 bv->text->FinishUndo();
893 case LFUN_PASTESELECTION:
895 string clip(bv->workarea()->getClipboard());
899 if (clip.find('\t') != string::npos) {
903 unsigned int len = clip.length();
904 string::size_type p = 0;
907 ((p = clip.find_first_of("\t\n", p)) != string::npos))
916 maxCols = max(cols, maxCols);
922 maxCols = max(cols, maxCols);
923 delete paste_tabular;
924 paste_tabular = new LyXTabular(this, rows, maxCols);
925 string::size_type op = 0;
927 int cells = paste_tabular->GetNumberOfCells();
929 while((cell < cells) && (p < len) &&
930 (p = clip.find_first_of("\t\n", p)) != string::npos)
936 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
941 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
942 while(cols++ < maxCols)
950 // check for the last cell if there is no trailing '\n'
951 if ((cell < cells) && (op < len))
952 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, len-op));
954 // so that the clipboard is used and it goes on to default
955 // and executes LFUN_PASTESELECTION in insettext!
956 delete paste_tabular;
961 if (hasPasteBuffer()) {
962 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
964 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
965 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
967 bv->text->cursor.par()->previous,
968 bv->text->cursor.par()->next
972 UpdateLocal(bv, INIT, true);
975 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
977 // we try to activate the actual inset and put this event down to
978 // the insets dispatch function.
979 result = UNDISPATCHED;
980 if (the_locking_inset)
982 if (ActivateCellInset(bv)) {
983 result=the_locking_inset->LocalDispatch(bv, action, arg);
984 if (result == DISPATCHED_NOUPDATE)
986 else if (result == DISPATCHED) {
987 the_locking_inset->ToggleInsetCursor(bv);
988 UpdateLocal(bv, CELL, false);
989 the_locking_inset->ToggleInsetCursor(bv);
992 result = UNDISPATCHED;
997 if (result!=FINISHED) {
998 if (!the_locking_inset) {
1002 bv->unlockInset(this);
1007 int InsetTabular::Latex(Buffer const * buf, ostream & os,
1008 bool fragile, bool fp) const
1010 return tabular->Latex(buf, os, fragile, fp);
1014 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
1016 // This should be changed to a real ascii export
1017 return tabular->Ascii(buf, os);
1021 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
1027 int InsetTabular::DocBook(Buffer const * buf, ostream & os) const
1029 return tabular->DocBook(buf,os);
1033 void InsetTabular::Validate(LaTeXFeatures & features) const
1035 tabular->Validate(features);
1039 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1040 LyXFont const & font,
1047 bool changed = false;
1049 // if we have a locking_inset we should have to check only this cell for
1050 // change so I'll try this to have a boost, but who knows ;)
1051 if ((need_update != INIT) &&
1052 (the_locking_inset == tabular->GetCellInset(actcell))) {
1053 for(int i = 0; i < tabular->columns(); ++i) {
1054 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1056 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1059 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1060 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1061 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1064 for (int i = 0; i < tabular->rows(); ++i) {
1067 for (int j= 0; j < tabular->columns(); ++j) {
1068 if (tabular->IsPartOfMultiColumn(i,j))
1071 inset = tabular->GetCellInset(cell);
1073 inset->update(bv, font, false);
1074 maxAsc = max(maxAsc, inset->ascent(bv, font));
1075 maxDesc = max(maxDesc, inset->descent(bv, font));
1076 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1078 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1079 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1085 void InsetTabular::GetCursorPos(BufferView *,
1086 int & x, int & y) const
1088 x = cursor.x() - top_x;
1093 void InsetTabular::ToggleInsetCursor(BufferView * bv)
1095 if (the_locking_inset) {
1096 the_locking_inset->ToggleInsetCursor(bv);
1100 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1102 int const asc = lyxfont::maxAscent(font);
1103 int const desc = lyxfont::maxDescent(font);
1106 bv->hideLockedInsetCursor();
1108 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1109 cursor_visible = !cursor_visible;
1113 void InsetTabular::ShowInsetCursor(BufferView * bv, bool show)
1115 if (!cursor_visible) {
1116 LyXFont font; // = GetFont(par, cursor.pos);
1118 int const asc = lyxfont::maxAscent(font);
1119 int const desc = lyxfont::maxDescent(font);
1120 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1122 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1123 cursor_visible = true;
1128 void InsetTabular::HideInsetCursor(BufferView * bv)
1130 if (cursor_visible) {
1131 bv->hideLockedInsetCursor();
1132 cursor_visible = false;
1134 // if (cursor_visible)
1135 // ToggleInsetCursor(bv);
1139 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1143 actcell = actrow = actcol = 0;
1144 int ly = tabular->GetDescentOfRow(actrow);
1146 // first search the right row
1147 while((ly < y) && (actrow < tabular->rows())) {
1148 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1149 tabular->GetAscentOfRow(actrow + 1) +
1150 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1153 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1155 actcell = tabular->GetCellNumber(actrow, actcol);
1157 // now search the right column
1158 int lx = tabular->GetWidthOfColumn(actcell) -
1159 tabular->GetAdditionalWidth(actcell);
1161 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1162 for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
1163 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1164 tabular->GetAdditionalWidth(actcell - 1));
1166 // Jürgen, you should check that this is correct. (Lgb)
1167 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1168 lx += tabular->GetWidthOfColumn(actcell + 1)
1169 + tabular->GetAdditionalWidth(actcell);
1173 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1178 int InsetTabular::getCellXPos(int cell) const
1182 for (; !tabular->IsFirstCellInRow(c); --c)
1184 int lx = tabular->GetWidthOfColumn(cell);
1185 for (; c < cell; ++c) {
1186 lx += tabular->GetWidthOfColumn(c);
1188 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1192 void InsetTabular::resetPos(BufferView * bv) const
1196 actcol = tabular->column_of_cell(actcell);
1201 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1202 if (tabular->IsLastCellInRow(cell)) {
1203 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1204 tabular->GetAscentOfRow(actrow + 1) +
1205 tabular->GetAdditionalHeight(cell + 1));
1209 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1210 int new_x = getCellXPos(actcell);
1211 int old_x = cursor.x();
1214 // cursor.x(getCellXPos(actcell) + offset);
1215 if (((cursor.x() - offset) > 20) &&
1216 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1217 (bv->workWidth()-20)))
1219 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1220 UpdateLocal(bv, FULL, false);
1221 } else if ((cursor.x() - offset) < 20) {
1222 scroll(bv, 20 - cursor.x() + offset);
1223 UpdateLocal(bv, FULL, false);
1224 } else if (scroll() && (top_x > 20) &&
1225 ((top_x+tabular->GetWidthOfTabular()) > (bv->workWidth()-20))) {
1226 scroll(bv, old_x - cursor.x());
1228 if ((!the_locking_inset ||
1229 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1230 (actcell != oldcell)) {
1231 InsetTabular * inset = const_cast<InsetTabular *>(this);
1232 bv->owner()->getDialogs()->updateTabular(inset);
1238 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1240 if (lock && !old_locking_inset) {
1241 if (ActivateCellInset(bv))
1244 bool moved = isRightToLeft(bv) ? movePrevCell(bv) : moveNextCell(bv);
1247 if (lock && ActivateCellInset(bv))
1251 return DISPATCHED_NOUPDATE;
1255 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1257 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1260 if (lock) { // behind the inset
1261 if (ActivateCellInset(bv, 0, 0, 0, true))
1265 return DISPATCHED_NOUPDATE;
1269 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1271 int const ocell = actcell;
1272 actcell = tabular->GetCellAbove(actcell);
1273 if (actcell == ocell) // we moved out of the inset
1279 if (old_locking_inset) {
1280 old_locking_inset->GetCursorPos(bv, x, y);
1281 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1283 if (ActivateCellInset(bv, x, 0))
1286 return DISPATCHED_NOUPDATE;
1290 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1292 int const ocell = actcell;
1293 actcell = tabular->GetCellBelow(actcell);
1294 if (actcell == ocell) // we moved out of the inset
1300 if (old_locking_inset) {
1301 old_locking_inset->GetCursorPos(bv, x, y);
1302 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1304 if (ActivateCellInset(bv, x, 0))
1307 return DISPATCHED_NOUPDATE;
1311 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1313 if (isRightToLeft(bv)) {
1314 if (tabular->IsFirstCellInRow(actcell)) {
1315 int row = tabular->row_of_cell(actcell);
1316 if (row == tabular->rows() - 1)
1318 actcell = tabular->GetLastCellInRow(row);
1319 actcell = tabular->GetCellBelow(actcell);
1326 if (tabular->IsLastCell(actcell))
1331 bool rtl = tabular->GetCellInset(actcell)->par->
1332 isRightToLeftPar(bv->buffer()->params);
1333 ActivateCellInset(bv, 0, 0, 0, !rtl);
1340 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1342 if (isRightToLeft(bv)) {
1343 if (tabular->IsLastCellInRow(actcell)) {
1344 int row = tabular->row_of_cell(actcell);
1347 actcell = tabular->GetFirstCellInRow(row);
1348 actcell = tabular->GetCellAbove(actcell);
1350 if (tabular->IsLastCell(actcell))
1355 if (!actcell) // first cell
1360 bool rtl = tabular->GetCellInset(actcell)->par->
1361 isRightToLeftPar(bv->buffer()->params);
1362 ActivateCellInset(bv, 0, 0, 0, !rtl);
1369 bool InsetTabular::Delete()
1375 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1377 if (the_locking_inset)
1378 the_locking_inset->SetFont(bv, font, tall);
1382 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1384 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1387 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1388 string const tmp = tabularFeatures[i].feature;
1390 if (tmp == what.substr(0, tmp.length())) {
1391 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1392 //tabularFeatures[i].feature.length())) {
1393 action = tabularFeatures[i].action;
1397 if (action == LyXTabular::LAST_ACTION)
1401 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1402 TabularFeatures(bv, action, val);
1407 void InsetTabular::TabularFeatures(BufferView * bv,
1408 LyXTabular::Feature feature,
1409 string const & value)
1418 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1419 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1424 case LyXTabular::M_ALIGN_LEFT:
1425 case LyXTabular::ALIGN_LEFT:
1426 setAlign=LYX_ALIGN_LEFT;
1428 case LyXTabular::M_ALIGN_RIGHT:
1429 case LyXTabular::ALIGN_RIGHT:
1430 setAlign=LYX_ALIGN_RIGHT;
1432 case LyXTabular::M_ALIGN_CENTER:
1433 case LyXTabular::ALIGN_CENTER:
1434 setAlign=LYX_ALIGN_CENTER;
1436 case LyXTabular::M_VALIGN_TOP:
1437 case LyXTabular::VALIGN_TOP:
1438 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1440 case LyXTabular::M_VALIGN_BOTTOM:
1441 case LyXTabular::VALIGN_BOTTOM:
1442 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1444 case LyXTabular::M_VALIGN_CENTER:
1445 case LyXTabular::VALIGN_CENTER:
1446 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1451 if (hasSelection()) {
1452 sel_col_start = tabular->column_of_cell(sel_cell_start);
1453 sel_col_end = tabular->column_of_cell(sel_cell_end);
1454 if (sel_col_start > sel_col_end) {
1455 sel_col_end = sel_col_start;
1456 sel_col_start = tabular->column_of_cell(sel_cell_end);
1458 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1461 sel_row_start = tabular->row_of_cell(sel_cell_start);
1462 sel_row_end = tabular->row_of_cell(sel_cell_end);
1463 if (sel_row_start > sel_row_end) {
1464 //int tmp = sel_row_start;
1465 //sel_row_start = sel_row_end;
1466 //sel_row_end = tmp;
1467 swap(sel_row_start, sel_row_end);
1470 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1471 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1473 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1475 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1476 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1478 bv->text->cursor.par()->previous,
1479 bv->text->cursor.par()->next
1483 int row = tabular->row_of_cell(actcell);
1484 int column = tabular->column_of_cell(actcell);
1488 case LyXTabular::SET_PWIDTH:
1490 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1491 tabular->SetColumnPWidth(actcell,value);
1493 for (int i=0; i < tabular->rows(); ++i) {
1494 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1497 UpdateLocal(bv, INIT, true);
1501 case LyXTabular::SET_MPWIDTH:
1503 bool const update = (tabular->GetPWidth(actcell) != value);
1504 tabular->SetMColumnPWidth(actcell,value);
1506 for (int i=0; i < tabular->rows(); ++i) {
1507 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1510 UpdateLocal(bv, INIT, true);
1514 case LyXTabular::SET_SPECIAL_COLUMN:
1515 case LyXTabular::SET_SPECIAL_MULTI:
1516 tabular->SetAlignSpecial(actcell,value,feature);
1518 case LyXTabular::APPEND_ROW:
1519 // append the row into the tabular
1520 UnlockInsetInInset(bv, the_locking_inset);
1521 tabular->AppendRow(actcell);
1522 UpdateLocal(bv, INIT, true);
1524 case LyXTabular::APPEND_COLUMN:
1525 // append the column into the tabular
1526 UnlockInsetInInset(bv, the_locking_inset);
1527 tabular->AppendColumn(actcell);
1528 actcell = tabular->GetCellNumber(row, column);
1529 UpdateLocal(bv, INIT, true);
1531 case LyXTabular::DELETE_ROW:
1532 UnlockInsetInInset(bv, the_locking_inset);
1533 tabular->DeleteRow(tabular->row_of_cell(actcell));
1534 if ((row+1) > tabular->rows())
1536 actcell = tabular->GetCellNumber(row, column);
1538 UpdateLocal(bv, INIT, true);
1540 case LyXTabular::DELETE_COLUMN:
1541 UnlockInsetInInset(bv, the_locking_inset);
1542 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1543 if ((column+1) > tabular->columns())
1545 actcell = tabular->GetCellNumber(row, column);
1547 UpdateLocal(bv, INIT, true);
1549 case LyXTabular::M_TOGGLE_LINE_TOP:
1551 case LyXTabular::TOGGLE_LINE_TOP:
1552 lineSet = !tabular->TopLine(actcell, flag);
1553 for (i=sel_row_start; i<=sel_row_end; ++i)
1554 for (j=sel_col_start; j<=sel_col_end; ++j)
1555 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1556 UpdateLocal(bv, INIT, true);
1559 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1561 case LyXTabular::TOGGLE_LINE_BOTTOM:
1562 lineSet = !tabular->BottomLine(actcell, flag);
1563 for (i=sel_row_start; i<=sel_row_end; ++i)
1564 for (j=sel_col_start; j<=sel_col_end; ++j)
1565 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1567 UpdateLocal(bv, INIT, true);
1570 case LyXTabular::M_TOGGLE_LINE_LEFT:
1572 case LyXTabular::TOGGLE_LINE_LEFT:
1573 lineSet = !tabular->LeftLine(actcell, flag);
1574 for (i=sel_row_start; i<=sel_row_end; ++i)
1575 for (j=sel_col_start; j<=sel_col_end; ++j)
1576 tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1578 UpdateLocal(bv, INIT, true);
1581 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1583 case LyXTabular::TOGGLE_LINE_RIGHT:
1584 lineSet = !tabular->RightLine(actcell, flag);
1585 for (i=sel_row_start; i<=sel_row_end; ++i)
1586 for (j=sel_col_start; j<=sel_col_end; ++j)
1587 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1589 UpdateLocal(bv, INIT, true);
1591 case LyXTabular::M_ALIGN_LEFT:
1592 case LyXTabular::M_ALIGN_RIGHT:
1593 case LyXTabular::M_ALIGN_CENTER:
1595 case LyXTabular::ALIGN_LEFT:
1596 case LyXTabular::ALIGN_RIGHT:
1597 case LyXTabular::ALIGN_CENTER:
1598 for (i = sel_row_start; i <= sel_row_end; ++i)
1599 for (j = sel_col_start; j <= sel_col_end; ++j)
1600 tabular->SetAlignment(tabular->GetCellNumber(i, j), setAlign,
1603 UpdateLocal(bv, INIT, true);
1605 UpdateLocal(bv, CELL, true);
1607 case LyXTabular::M_VALIGN_TOP:
1608 case LyXTabular::M_VALIGN_BOTTOM:
1609 case LyXTabular::M_VALIGN_CENTER:
1611 case LyXTabular::VALIGN_TOP:
1612 case LyXTabular::VALIGN_BOTTOM:
1613 case LyXTabular::VALIGN_CENTER:
1614 for (i = sel_row_start; i <= sel_row_end; ++i)
1615 for (j = sel_col_start; j <= sel_col_end; ++j)
1616 tabular->SetVAlignment(tabular->GetCellNumber(i, j),
1619 UpdateLocal(bv, INIT, true);
1621 UpdateLocal(bv, CELL, true);
1623 case LyXTabular::MULTICOLUMN:
1625 if (sel_row_start != sel_row_end) {
1626 WriteAlert(_("Impossible Operation!"),
1627 _("Multicolumns can only be horizontally."),
1631 // just multicol for one Single Cell
1632 if (!hasSelection()) {
1633 // check wether we are completly in a multicol
1634 if (tabular->IsMultiColumn(actcell)) {
1635 tabular->UnsetMultiColumn(actcell);
1636 UpdateLocal(bv, INIT, true);
1638 tabular->SetMultiColumn(actcell, 1);
1639 UpdateLocal(bv, CELL, true);
1643 // we have a selection so this means we just add all this
1644 // cells to form a multicolumn cell
1648 if (sel_cell_start > sel_cell_end) {
1649 s_start = sel_cell_end;
1650 s_end = sel_cell_start;
1652 s_start = sel_cell_start;
1653 s_end = sel_cell_end;
1655 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1657 sel_cell_end = sel_cell_start;
1658 UpdateLocal(bv, INIT, true);
1661 case LyXTabular::SET_ALL_LINES:
1663 case LyXTabular::UNSET_ALL_LINES:
1664 for (i=sel_row_start; i<=sel_row_end; ++i)
1665 for (j=sel_col_start; j<=sel_col_end; ++j)
1666 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1667 UpdateLocal(bv, INIT, true);
1669 case LyXTabular::SET_LONGTABULAR:
1670 tabular->SetLongTabular(true);
1671 UpdateLocal(bv, INIT, true); // because this toggles displayed
1673 case LyXTabular::UNSET_LONGTABULAR:
1674 tabular->SetLongTabular(false);
1675 UpdateLocal(bv, INIT, true); // because this toggles displayed
1677 case LyXTabular::SET_ROTATE_TABULAR:
1678 tabular->SetRotateTabular(true);
1680 case LyXTabular::UNSET_ROTATE_TABULAR:
1681 tabular->SetRotateTabular(false);
1683 case LyXTabular::SET_ROTATE_CELL:
1684 for (i=sel_row_start; i<=sel_row_end; ++i)
1685 for (j=sel_col_start; j<=sel_col_end; ++j)
1686 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1688 case LyXTabular::UNSET_ROTATE_CELL:
1689 for (i = sel_row_start; i <= sel_row_end; ++i)
1690 for (j = sel_col_start; j <= sel_col_end; ++j)
1691 tabular->SetRotateCell(tabular->GetCellNumber(i, j), false);
1693 case LyXTabular::SET_USEBOX:
1695 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1696 if (val == tabular->GetUsebox(actcell))
1697 val = LyXTabular::BOX_NONE;
1698 for (i = sel_row_start; i <= sel_row_end; ++i)
1699 for (j = sel_col_start; j <= sel_col_end; ++j)
1700 tabular->SetUsebox(tabular->GetCellNumber(i, j), val);
1703 case LyXTabular::SET_LTFIRSTHEAD:
1704 tabular->SetLTHead(actcell, true);
1706 case LyXTabular::SET_LTHEAD:
1707 tabular->SetLTHead(actcell, false);
1709 case LyXTabular::SET_LTFOOT:
1710 tabular->SetLTFoot(actcell, false);
1712 case LyXTabular::SET_LTLASTFOOT:
1713 tabular->SetLTFoot(actcell, true);
1715 case LyXTabular::SET_LTNEWPAGE:
1716 what = !tabular->GetLTNewPage(actcell);
1717 tabular->SetLTNewPage(actcell, what);
1719 // dummy stuff just to avoid warnings
1720 case LyXTabular::LAST_ACTION:
1726 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1729 UpdatableInset * inset =
1730 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1731 LyXFont font(LyXFont::ALL_SANE);
1733 x = inset->x() + inset->width(bv, font);
1734 y = inset->descent(bv, font);
1736 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1737 //inset_y = cursor.y();
1738 inset->Edit(bv, x, y, button);
1739 if (!the_locking_inset)
1741 UpdateLocal(bv, CELL, false);
1742 return (the_locking_inset != 0);
1746 bool InsetTabular::ActivateCellInsetAbs(BufferView * bv, int x, int y,
1749 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1750 inset_y = cursor.y();
1751 return ActivateCellInset(bv, x - inset_x, y - inset_y, button);
1755 bool InsetTabular::InsetHit(BufferView *, int x, int) const
1757 return x + top_x > cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1761 // This returns paperWidth() if the cell-width is unlimited or the width
1762 // in pixels if we have a pwidth for this cell.
1763 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1765 string const s = tabular->GetPWidth(cell);
1769 return VSpace(s).inPixels(0, 0);
1773 int InsetTabular::getMaxWidth(Painter & pain,
1774 UpdatableInset const * inset) const
1776 int const n = tabular->GetNumberOfCells();
1778 for (; cell < n; ++cell) {
1779 if (tabular->GetCellInset(cell) == inset)
1784 int w = GetMaxWidthOfCell(pain, cell);
1786 // because the inset then subtracts it's top_x and owner->x()
1787 w += (inset->x() - top_x);
1792 void InsetTabular::resizeLyXText(BufferView *) const
1798 LyXText * InsetTabular::getLyXText(BufferView const * bv) const
1800 if (the_locking_inset)
1801 return the_locking_inset->getLyXText(bv);
1802 return Inset::getLyXText(bv);
1806 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1808 if (the_locking_inset) {
1809 InsetTabular * i = static_cast<InsetTabular *>
1810 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1812 i->OpenLayoutDialog(bv);
1816 bv->owner()->getDialogs()->showTabular(const_cast<InsetTabular *>(this));
1820 // functions returns:
1824 // 3 ... toggled off
1826 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1828 int action = LyXTabular::LAST_ACTION;
1829 LyXFunc::func_status status = LyXFunc::OK;
1832 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1833 string const tmp = tabularFeatures[i].feature;
1834 if (tmp == what.substr(0, tmp.length())) {
1835 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1836 // tabularFeatures[i].feature.length())) {
1837 action = tabularFeatures[i].action;
1841 if (action == LyXTabular::LAST_ACTION)
1842 return LyXFunc::Unknown;
1844 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1846 int sel_row_start, sel_row_end;
1850 if (hasSelection()) {
1851 sel_row_start = tabular->row_of_cell(sel_cell_start);
1852 sel_row_end = tabular->row_of_cell(sel_cell_end);
1853 if (sel_row_start > sel_row_end) {
1854 //int tmp = sel_row_start;
1855 //sel_row_start = sel_row_end;
1856 //sel_row_end = tmp;
1857 swap(sel_row_start, sel_row_end);
1860 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1864 case LyXTabular::SET_PWIDTH:
1865 case LyXTabular::SET_MPWIDTH:
1866 case LyXTabular::SET_SPECIAL_COLUMN:
1867 case LyXTabular::SET_SPECIAL_MULTI:
1868 status |= LyXFunc::Disabled;
1871 case LyXTabular::APPEND_ROW:
1872 case LyXTabular::APPEND_COLUMN:
1873 case LyXTabular::DELETE_ROW:
1874 case LyXTabular::DELETE_COLUMN:
1875 case LyXTabular::SET_ALL_LINES:
1876 case LyXTabular::UNSET_ALL_LINES:
1877 status |= LyXFunc::OK;
1880 case LyXTabular::MULTICOLUMN:
1881 if (tabular->IsMultiColumn(actcell))
1882 status |= LyXFunc::ToggleOn;
1884 status |= LyXFunc::ToggleOff;
1886 case LyXTabular::M_TOGGLE_LINE_TOP:
1888 case LyXTabular::TOGGLE_LINE_TOP:
1889 if (tabular->TopLine(actcell, flag))
1890 status |= LyXFunc::ToggleOn;
1892 status |= LyXFunc::ToggleOff;
1894 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1896 case LyXTabular::TOGGLE_LINE_BOTTOM:
1897 if (tabular->BottomLine(actcell, flag))
1898 status |= LyXFunc::ToggleOn;
1900 status |= LyXFunc::ToggleOff;
1902 case LyXTabular::M_TOGGLE_LINE_LEFT:
1904 case LyXTabular::TOGGLE_LINE_LEFT:
1905 if (tabular->LeftLine(actcell, flag))
1906 status |= LyXFunc::ToggleOn;
1908 status |= LyXFunc::ToggleOff;
1910 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1912 case LyXTabular::TOGGLE_LINE_RIGHT:
1913 if (tabular->RightLine(actcell, flag))
1914 status |= LyXFunc::ToggleOn;
1916 status |= LyXFunc::ToggleOff;
1918 case LyXTabular::M_ALIGN_LEFT:
1920 case LyXTabular::ALIGN_LEFT:
1921 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1922 status |= LyXFunc::ToggleOn;
1924 status |= LyXFunc::ToggleOff;
1926 case LyXTabular::M_ALIGN_RIGHT:
1928 case LyXTabular::ALIGN_RIGHT:
1929 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1930 status |= LyXFunc::ToggleOn;
1932 status |= LyXFunc::ToggleOff;
1934 case LyXTabular::M_ALIGN_CENTER:
1936 case LyXTabular::ALIGN_CENTER:
1937 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1938 status |= LyXFunc::ToggleOn;
1940 status |= LyXFunc::ToggleOff;
1942 case LyXTabular::M_VALIGN_TOP:
1944 case LyXTabular::VALIGN_TOP:
1945 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1946 status |= LyXFunc::ToggleOn;
1948 status |= LyXFunc::ToggleOff;
1950 case LyXTabular::M_VALIGN_BOTTOM:
1952 case LyXTabular::VALIGN_BOTTOM:
1953 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1954 status |= LyXFunc::ToggleOn;
1956 status |= LyXFunc::ToggleOff;
1958 case LyXTabular::M_VALIGN_CENTER:
1960 case LyXTabular::VALIGN_CENTER:
1961 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1962 status |= LyXFunc::ToggleOn;
1964 status |= LyXFunc::ToggleOff;
1966 case LyXTabular::SET_LONGTABULAR:
1967 if (tabular->IsLongTabular())
1968 status |= LyXFunc::ToggleOn;
1970 status |= LyXFunc::ToggleOff;
1972 case LyXTabular::UNSET_LONGTABULAR:
1973 if (!tabular->IsLongTabular())
1974 status |= LyXFunc::ToggleOn;
1976 status |= LyXFunc::ToggleOff;
1978 case LyXTabular::SET_ROTATE_TABULAR:
1979 if (tabular->GetRotateTabular())
1980 status |= LyXFunc::ToggleOn;
1982 status |= LyXFunc::ToggleOff;
1984 case LyXTabular::UNSET_ROTATE_TABULAR:
1985 if (!tabular->GetRotateTabular())
1986 status |= LyXFunc::ToggleOn;
1988 status |= LyXFunc::ToggleOff;
1990 case LyXTabular::SET_ROTATE_CELL:
1991 if (tabular->GetRotateCell(actcell))
1992 status |= LyXFunc::ToggleOn;
1994 status |= LyXFunc::ToggleOff;
1996 case LyXTabular::UNSET_ROTATE_CELL:
1997 if (!tabular->GetRotateCell(actcell))
1998 status |= LyXFunc::ToggleOn;
2000 status |= LyXFunc::ToggleOff;
2002 case LyXTabular::SET_USEBOX:
2003 if (strToInt(argument) == tabular->GetUsebox(actcell))
2004 status |= LyXFunc::ToggleOn;
2006 status |= LyXFunc::ToggleOff;
2008 case LyXTabular::SET_LTFIRSTHEAD:
2009 if (tabular->GetRowOfLTHead(actcell, dummy))
2010 status |= LyXFunc::ToggleOn;
2012 status |= LyXFunc::ToggleOff;
2014 case LyXTabular::SET_LTHEAD:
2015 if (tabular->GetRowOfLTHead(actcell, dummy))
2016 status |= LyXFunc::ToggleOn;
2018 status |= LyXFunc::ToggleOff;
2020 case LyXTabular::SET_LTFOOT:
2021 if (tabular->GetRowOfLTFoot(actcell, dummy))
2022 status |= LyXFunc::ToggleOn;
2024 status |= LyXFunc::ToggleOff;
2026 case LyXTabular::SET_LTLASTFOOT:
2027 if (tabular->GetRowOfLTFoot(actcell, dummy))
2028 status |= LyXFunc::ToggleOn;
2030 status |= LyXFunc::ToggleOff;
2032 case LyXTabular::SET_LTNEWPAGE:
2033 if (tabular->GetLTNewPage(actcell))
2034 status |= LyXFunc::ToggleOn;
2036 status |= LyXFunc::ToggleOff;
2039 status = LyXFunc::Disabled;
2046 bool InsetTabular::copySelection(BufferView * bv)
2048 if (!hasSelection())
2050 delete paste_tabular;
2052 int sel_col_start, sel_col_end;
2053 int sel_row_start, sel_row_end;
2055 sel_col_start = tabular->column_of_cell(sel_cell_start);
2056 sel_col_end = tabular->column_of_cell(sel_cell_end);
2057 if (sel_col_start > sel_col_end) {
2058 sel_col_start = sel_col_end;
2059 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2061 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2063 int columns = sel_col_end - sel_col_start + 1;
2065 sel_row_start = tabular->row_of_cell(sel_cell_start);
2066 sel_row_end = tabular->row_of_cell(sel_cell_end);
2067 if (sel_row_start > sel_row_end) {
2068 //int tmp tmp = sel_row_start;
2069 //sel_row_start = sel_row_end;
2070 //sel_row_end = tmp;
2071 swap(sel_row_start, sel_row_end);
2073 int rows = sel_row_end - sel_row_start + 1;
2075 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2077 for (i=0; i < sel_row_start; ++i)
2078 paste_tabular->DeleteRow(0);
2079 while(paste_tabular->rows() > rows)
2080 paste_tabular->DeleteRow(rows);
2081 paste_tabular->SetTopLine(0, true, true);
2082 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2084 for (i=0; i < sel_col_start; ++i)
2085 paste_tabular->DeleteColumn(0);
2086 while(paste_tabular->columns() > columns)
2087 paste_tabular->DeleteColumn(columns);
2088 paste_tabular->SetLeftLine(0, true, true);
2089 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),true, true);
2092 paste_tabular->Ascii(bv->buffer(), sstr);
2093 bv->stuffClipboard(sstr.str().c_str());
2098 bool InsetTabular::pasteSelection(BufferView * bv)
2103 for (int r1 = 0, r2 = actrow;
2104 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2107 for(int c1 = 0, c2 = actcol;
2108 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2111 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2112 tabular->IsPartOfMultiColumn(r2,c2))
2114 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2118 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2122 int n1 = paste_tabular->GetCellNumber(r1, c1);
2123 int n2 = tabular->GetCellNumber(r2, c2);
2124 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2125 tabular->GetCellInset(n2)->setOwner(this);
2126 tabular->GetCellInset(n2)->deleteLyXText(bv);
2133 bool InsetTabular::cutSelection()
2135 if (!hasSelection())
2138 int sel_col_start, sel_col_end;
2139 int sel_row_start, sel_row_end;
2141 sel_col_start = tabular->column_of_cell(sel_cell_start);
2142 sel_col_end = tabular->column_of_cell(sel_cell_end);
2143 if (sel_col_start > sel_col_end) {
2144 sel_col_start = sel_col_end;
2145 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2147 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2149 sel_row_start = tabular->row_of_cell(sel_cell_start);
2150 sel_row_end = tabular->row_of_cell(sel_cell_end);
2151 if (sel_row_start > sel_row_end) {
2152 //int tmp = sel_row_start;
2153 //sel_row_start = sel_row_end;
2154 //sel_row_end = tmp;
2155 swap(sel_row_start, sel_row_end);
2157 if (sel_cell_start > sel_cell_end) {
2158 //int tmp = sel_cell_start;
2159 //sel_cell_start = sel_cell_end;
2160 //sel_cell_end = tmp;
2161 swap(sel_cell_start, sel_cell_end);
2163 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2164 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2165 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2171 bool InsetTabular::isRightToLeft(BufferView *bv )
2173 return bv->getParentLanguage(this)->RightToLeft();