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;
133 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
136 tabular = new LyXTabular(this, *(tab.tabular));
137 the_locking_inset = 0;
138 locked = no_selection = cursor_visible = false;
141 actrow = actcell = 0;
142 sel_cell_start = sel_cell_end = 0;
148 InsetTabular::~InsetTabular()
155 Inset * InsetTabular::Clone(Buffer const & buf) const
157 InsetTabular * t = new InsetTabular(*this, buf);
159 t->tabular = tabular->Clone(t);
164 void InsetTabular::Write(Buffer const * buf, ostream & os) const
166 os << " Tabular" << endl;
167 tabular->Write(buf, os);
171 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
173 bool old_format = (lex.GetString() == "\\LyXTable");
178 tabular = new LyXTabular(buf, this, lex);
186 token = lex.GetString();
187 while (lex.IsOK() && (token != "\\end_inset")) {
189 token = lex.GetString();
191 if (token != "\\end_inset") {
192 lex.printError("Missing \\end_inset at this point. "
198 int InsetTabular::ascent(BufferView *, LyXFont const &) const
200 return tabular->GetAscentOfRow(0);
204 int InsetTabular::descent(BufferView *, LyXFont const &) const
206 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
210 int InsetTabular::width(BufferView *, LyXFont const &) const
212 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
216 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
217 float & x, bool cleared) const
222 Painter & pain = bv->painter();
226 UpdatableInset::draw(bv, font, baseline, x, cleared);
227 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
228 (top_x != int(x)) || (top_baseline != baseline))) {
229 int h = ascent(bv, font) + descent(bv, font);
230 int tx = display() || !owner() ? 0 : top_x;
231 int w = tx ? width(bv, font) : pain.paperWidth();
232 int ty = baseline - ascent(bv, font);
236 if ((ty + h) > pain.paperHeight())
237 h = pain.paperHeight();
238 if ((top_x + w) > pain.paperWidth())
239 w = pain.paperWidth();
240 pain.fillRectangle(tx, ty, w, h);
245 top_baseline = baseline;
246 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
249 x += ADD_TO_TABULAR_WIDTH;
253 for (i = 0; i < tabular->rows(); ++i) {
255 dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
256 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight();
257 for (j = 0; j < tabular->columns(); ++j) {
258 if (tabular->IsPartOfMultiColumn(i, j))
260 cx = nx + tabular->GetBeginningOfTextInCell(cell);
263 DrawCellSelection(pain, nx, baseline, i, j, cell);
264 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
266 DrawCellLines(pain, nx, baseline, i, cell);
268 nx += tabular->GetWidthOfColumn(cell);
271 baseline += tabular->GetDescentOfRow(i) +
272 tabular->GetAscentOfRow(i + 1) +
273 tabular->GetAdditionalHeight(cell);
275 } else if (need_update == CELL) {
278 if (the_locking_inset) {
279 Inset * inset = tabular->GetCellInset(cell);
280 for (i = 0; (inset != the_locking_inset) && (i < tabular->rows());
283 for (j = 0; (inset != the_locking_inset) && (j < tabular->columns()); ++j)
285 if (tabular->IsPartOfMultiColumn(i, j))
287 nx += tabular->GetWidthOfColumn(cell);
289 inset = tabular->GetCellInset(cell);
291 if (tabular->row_of_cell(cell) > i) {
293 baseline += tabular->GetDescentOfRow(i) +
294 tabular->GetAscentOfRow(i + 1) +
295 tabular->GetAdditionalHeight(cell);
299 for (i = 0; (cell < actcell) && (i < tabular->rows()); ++i) {
300 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
301 if (tabular->IsPartOfMultiColumn(i, j))
303 nx += tabular->GetWidthOfColumn(cell);
306 if (tabular->row_of_cell(cell) > i) {
308 baseline += tabular->GetDescentOfRow(i) +
309 tabular->GetAscentOfRow(i + 1) +
310 tabular->GetAdditionalHeight(cell);
314 i = tabular->row_of_cell(cell);
315 if (the_locking_inset != tabular->GetCellInset(cell)) {
316 lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
321 cx = dx = nx + tabular->GetBeginningOfTextInCell(cell);
322 tabular->GetCellInset(cell)->draw(bv,font,baseline, dx, false);
323 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
325 // clear only if we didn't have a change
326 if (need_update == CELL) {
327 // clear before the inset
330 baseline - tabular->GetAscentOfRow(i) + 1,
332 tabular->GetAscentOfRow(i) +
333 tabular->GetDescentOfRow(i) - 1);
334 // clear behind the inset
336 int(cx + the_locking_inset->width(bv,font) + 1),
337 baseline - tabular->GetAscentOfRow(i) + 1,
338 tabular->GetWidthOfColumn(cell) -
339 tabular->GetBeginningOfTextInCell(cell) -
340 the_locking_inset->width(bv,font) -
341 tabular->GetAdditionalWidth(cell) - 1,
342 tabular->GetAscentOfRow(i) +
343 tabular->GetDescentOfRow(i) - 1);
346 x -= ADD_TO_TABULAR_WIDTH;
347 x += width(bv, font);
348 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
355 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
356 int row, int cell) const
358 int x2 = x + tabular->GetWidthOfColumn(cell);
361 if (!tabular->TopAlreadyDrawed(cell)) {
362 on_off = !tabular->TopLine(cell);
363 pain.line(x, baseline - tabular->GetAscentOfRow(row),
364 x2, baseline - tabular->GetAscentOfRow(row),
365 on_off ? LColor::tabularonoffline : LColor::tabularline,
366 on_off ? Painter::line_onoffdash : Painter::line_solid);
368 on_off = !tabular->BottomLine(cell);
369 pain.line(x,baseline + tabular->GetDescentOfRow(row),
370 x2, baseline + tabular->GetDescentOfRow(row),
371 on_off ? LColor::tabularonoffline : LColor::tabularline,
372 on_off ? Painter::line_onoffdash : Painter::line_solid);
373 if (!tabular->LeftAlreadyDrawed(cell)) {
374 on_off = !tabular->LeftLine(cell);
375 pain.line(x, baseline - tabular->GetAscentOfRow(row),
376 x, baseline + tabular->GetDescentOfRow(row),
377 on_off ? LColor::tabularonoffline : LColor::tabularline,
378 on_off ? Painter::line_onoffdash : Painter::line_solid);
380 on_off = !tabular->RightLine(cell);
381 pain.line(x2 - tabular->GetAdditionalWidth(cell),
382 baseline - tabular->GetAscentOfRow(row),
383 x2 - tabular->GetAdditionalWidth(cell),
384 baseline + tabular->GetDescentOfRow(row),
385 on_off ? LColor::tabularonoffline : LColor::tabularline,
386 on_off ? Painter::line_onoffdash : Painter::line_solid);
390 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
391 int row, int column, int cell) const
393 int cs = tabular->column_of_cell(sel_cell_start);
394 int ce = tabular->column_of_cell(sel_cell_end);
397 cs = tabular->column_of_cell(sel_cell_end);
399 ce = tabular->right_column_of_cell(sel_cell_end);
402 int rs = tabular->row_of_cell(sel_cell_start);
403 int re = tabular->row_of_cell(sel_cell_end);
404 if (rs > re) swap(rs, re);
406 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
407 int w = tabular->GetWidthOfColumn(cell);
408 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
409 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
410 w, h, LColor::selection);
415 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
419 calculate_dimensions_of_cells(bv, font, true);
421 owner()->update(bv, font, true);
424 if (the_locking_inset) {
425 the_locking_inset->update(bv, font, reinit);
427 // inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
428 // inset_y = cursor.y();
430 switch (need_update) {
434 if (calculate_dimensions_of_cells(bv, font, false))
446 string const InsetTabular::EditMessage() const
448 return _("Opened Tabular Inset");
452 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
454 UpdatableInset::Edit(bv, x, y, button);
456 if (!bv->lockInset(this)) {
457 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
461 the_locking_inset = 0;
465 sel_cell_start = sel_cell_end = actcell;
466 bv->text->FinishUndo();
467 if (InsetHit(bv, x, y) && (button != 3)) {
468 ActivateCellInsetAbs(bv, x, y, button);
470 // UpdateLocal(bv, NONE, false);
471 // bv->getOwner()->getPopups().updateFormTabular();
475 void InsetTabular::InsetUnlock(BufferView * bv)
477 if (the_locking_inset) {
478 the_locking_inset->InsetUnlock(bv);
479 the_locking_inset = 0;
482 no_selection = false;
485 if (scroll() || hasSelection()) {
489 sel_cell_start = sel_cell_end = 0;
491 UpdateLocal(bv, FULL, false);
496 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
497 bool mark_dirty) const
499 if (need_update < what) // only set this if it has greater update
501 if ((what == INIT) && hasSelection())
504 if (need_update != NONE) {
505 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
506 if (locked) // && (what != NONE))
512 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
514 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
518 if (inset == tabular->GetCellInset(actcell)) {
519 lyxerr[Debug::INSETS] << "OK" << endl;
520 the_locking_inset = tabular->GetCellInset(actcell);
522 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
523 inset_y = cursor.y();
525 } else if (the_locking_inset && (the_locking_inset == inset)) {
526 lyxerr[Debug::INSETS] << "OK" << endl;
528 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
529 inset_y = cursor.y();
530 } else if (the_locking_inset) {
531 lyxerr[Debug::INSETS] << "MAYBE" << endl;
532 return the_locking_inset->LockInsetInInset(bv, inset);
534 lyxerr[Debug::INSETS] << "NOT OK" << endl;
539 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
542 if (!the_locking_inset)
544 if (the_locking_inset == inset) {
545 the_locking_inset->InsetUnlock(bv);
546 the_locking_inset = 0;
547 UpdateLocal(bv, CELL, false);
548 ShowInsetCursor(bv, false);
551 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
552 if (inset->LyxCode() == TABULAR_CODE &&
553 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
555 bv->owner()->getDialogs()->updateTabular(this);
564 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
566 if (!the_locking_inset)
568 if (the_locking_inset != inset) {
569 if (!the_locking_inset->UpdateInsetInInset(bv, inset))
572 UpdateLocal(bv, CELL, false);
577 unsigned int InsetTabular::InsetInInsetY()
579 if (!the_locking_inset)
582 return (inset_y + the_locking_inset->InsetInInsetY());
586 UpdatableInset * InsetTabular::GetLockingInset()
588 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
592 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
596 if (the_locking_inset)
597 return the_locking_inset->GetFirstLockingInsetOfType(c);
602 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
604 if (the_locking_inset)
605 return the_locking_inset->InsertInset(bv, inset);
610 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
612 if (hasSelection() && (button == 3))
615 if (hasSelection()) {
617 UpdateLocal(bv, SELECTION, false);
620 no_selection = false;
622 int const ocell = actcell;
623 int const orow = actrow;
628 UpdateLocal(bv, NONE, false);
629 sel_cell_start = sel_cell_end = actcell;
631 if ((ocell != actcell) && the_locking_inset) {
632 the_locking_inset->InsetUnlock(bv);
633 the_locking_inset = 0;
639 bool const inset_hit = InsetHit(bv, x, y);
641 if ((ocell == actcell) && the_locking_inset && inset_hit) {
643 the_locking_inset->InsetButtonPress(bv,
644 x - inset_x, y - inset_y, button);
646 } else if (the_locking_inset) {
647 the_locking_inset->InsetUnlock(bv);
649 the_locking_inset = 0;
651 LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph");
654 if (inset_hit && bv->theLockingInset()) {
655 if (ActivateCellInsetAbs(bv, x, y, button))
656 the_locking_inset->InsetButtonPress(bv, x - inset_x,
657 y - inset_y, button);
664 void InsetTabular::InsetButtonRelease(BufferView * bv,
665 int x, int y, int button)
668 if (the_locking_inset) {
670 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
671 i->InsetButtonRelease(bv, x, y, button);
675 bv->owner()->getDialogs()->showTabular(this);
678 if (the_locking_inset) {
679 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
682 no_selection = false;
686 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
688 if (the_locking_inset) {
689 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
690 y - inset_y, button);
695 int const old_cell = actcell;
698 sel_cell_end = actcell;
699 if (sel_cell_end != old_cell)
700 UpdateLocal(bv, SELECTION, false);
703 no_selection = false;
707 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
709 if (the_locking_inset) {
710 the_locking_inset->InsetKeyPress(xke);
716 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
719 // We need to save the value of the_locking_inset as the call to
720 // the_locking_inset->LocalDispatch might unlock it.
721 old_locking_inset = the_locking_inset;
722 no_selection = false;
723 UpdatableInset::RESULT result =
724 UpdatableInset::LocalDispatch(bv, action, arg);
725 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
730 if ((action < 0) && arg.empty())
733 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
734 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
736 if (the_locking_inset) {
737 result=the_locking_inset->LocalDispatch(bv, action, arg);
738 if (result == DISPATCHED_NOUPDATE)
740 else if (result == DISPATCHED) {
741 the_locking_inset->ToggleInsetCursor(bv);
742 UpdateLocal(bv, CELL, false);
743 the_locking_inset->ToggleInsetCursor(bv);
745 } else if (result == FINISHED) {
749 bool hs = hasSelection();
753 // --- Cursor Movements ---------------------------------------------
755 if (tabular->IsLastCellInRow(actcell))
757 moveRight(bv, false);
758 sel_cell_end = actcell;
759 UpdateLocal(bv, SELECTION, false);
762 result = moveRight(bv);
763 sel_cell_start = sel_cell_end = actcell;
765 UpdateLocal(bv, SELECTION, false);
768 if (tabular->IsFirstCellInRow(actcell))
771 sel_cell_end = actcell;
772 UpdateLocal(bv, SELECTION, false);
775 result = moveLeft(bv);
776 sel_cell_start = sel_cell_end = actcell;
778 UpdateLocal(bv, SELECTION, false);
782 int const ocell = actcell;
784 if ((ocell == sel_cell_end) ||
785 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
786 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
788 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
789 UpdateLocal(bv, SELECTION, false);
793 result = moveDown(bv, old_locking_inset != 0);
794 sel_cell_start = sel_cell_end = actcell;
796 UpdateLocal(bv, SELECTION, false);
800 int const ocell = actcell;
802 if ((ocell == sel_cell_end) ||
803 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
804 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
806 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
807 UpdateLocal(bv, SELECTION, false);
811 result = moveUp(bv, old_locking_inset != 0);
812 sel_cell_start = sel_cell_end = actcell;
814 UpdateLocal(bv, SELECTION, false);
827 if (the_locking_inset) {
828 UnlockInsetInInset(bv, the_locking_inset);
829 the_locking_inset = 0;
831 if (action == LFUN_TAB)
832 moveNextCell(bv, old_locking_inset != 0);
834 movePrevCell(bv, old_locking_inset != 0);
835 sel_cell_start = sel_cell_end = actcell;
837 UpdateLocal(bv, SELECTION, false);
840 case LFUN_LAYOUT_TABULAR:
842 bv->owner()->getDialogs()->showTabular(this);
845 case LFUN_TABULAR_FEATURE:
846 if (!TabularFeatures(bv, arg))
847 result = UNDISPATCHED;
850 if (!copySelection(bv))
852 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
854 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
855 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
857 bv->text->cursor.par()->previous,
858 bv->text->cursor.par()->next
862 UpdateLocal(bv, INIT, true);
867 bv->text->FinishUndo();
870 case LFUN_PASTESELECTION:
872 string clip(bv->workarea()->getClipboard());
876 if (clip.find('\t') != string::npos) {
880 unsigned int len = clip.length();
881 string::size_type p = 0;
884 ((p = clip.find_first_of("\t\n", p)) != string::npos))
893 maxCols = max(cols, maxCols);
899 maxCols = max(cols, maxCols);
900 delete paste_tabular;
901 paste_tabular = new LyXTabular(this, rows, maxCols);
902 string::size_type op = 0;
904 int cells = paste_tabular->GetNumberOfCells();
906 while((cell < cells) && (p < len) &&
907 (p = clip.find_first_of("\t\n", p)) != string::npos)
913 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
918 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
919 while(cols++ < maxCols)
927 // check for the last cell if there is no trailing '\n'
928 if ((cell < cells) && (op < len))
929 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, len-op));
931 // so that the clipboard is used and it goes on to default
932 // and executes LFUN_PASTESELECTION in insettext!
933 delete paste_tabular;
938 if (hasPasteBuffer()) {
939 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
941 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
942 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
944 bv->text->cursor.par()->previous,
945 bv->text->cursor.par()->next
949 UpdateLocal(bv, INIT, true);
952 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
954 // we try to activate the actual inset and put this event down to
955 // the insets dispatch function.
956 result = UNDISPATCHED;
957 if (the_locking_inset)
960 if (ActivateCellInset(bv)) {
961 result=the_locking_inset->LocalDispatch(bv, action, arg);
962 if ((result == UNDISPATCHED) || (result == FINISHED)) {
963 UnlockInsetInInset(bv, the_locking_inset);
965 the_locking_inset = 0;
969 the_locking_inset->ToggleInsetCursor(bv);
970 UpdateLocal(bv, CELL, false);
971 the_locking_inset->ToggleInsetCursor(bv);
976 if (result!=FINISHED) {
977 if (!the_locking_inset) {
981 bv->unlockInset(this);
986 int InsetTabular::Latex(Buffer const * buf, ostream & os,
987 bool fragile, bool fp) const
989 return tabular->Latex(buf, os, fragile, fp);
993 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
995 // This should be changed to a real ascii export
996 return tabular->Ascii(buf, os);
1000 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
1006 int InsetTabular::DocBook(Buffer const * buf, ostream & os) const
1008 return tabular->DocBook(buf,os);
1012 void InsetTabular::Validate(LaTeXFeatures & features) const
1014 tabular->Validate(features);
1018 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1019 LyXFont const & font,
1026 bool changed = false;
1028 // if we have a locking_inset we should have to check only this cell for
1029 // change so I'll try this to have a boost, but who knows ;)
1030 if ((need_update != INIT) &&
1031 (the_locking_inset == tabular->GetCellInset(actcell))) {
1032 for(int i = 0; i < tabular->columns(); ++i) {
1033 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1035 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1038 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1039 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1040 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1043 for (int i = 0; i < tabular->rows(); ++i) {
1046 for (int j= 0; j < tabular->columns(); ++j) {
1047 if (tabular->IsPartOfMultiColumn(i,j))
1050 inset = tabular->GetCellInset(cell);
1052 inset->update(bv, font, false);
1053 maxAsc = max(maxAsc, inset->ascent(bv, font));
1054 maxDesc = max(maxDesc, inset->descent(bv, font));
1055 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1057 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1058 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1064 void InsetTabular::GetCursorPos(BufferView *,
1065 int & x, int & y) const
1067 x = cursor.x() - top_x;
1072 void InsetTabular::ToggleInsetCursor(BufferView * bv)
1074 if (the_locking_inset) {
1075 the_locking_inset->ToggleInsetCursor(bv);
1079 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1081 int const asc = lyxfont::maxAscent(font);
1082 int const desc = lyxfont::maxDescent(font);
1085 bv->hideLockedInsetCursor();
1087 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1088 cursor_visible = !cursor_visible;
1092 void InsetTabular::ShowInsetCursor(BufferView * bv, bool show)
1094 if (!cursor_visible) {
1095 LyXFont font; // = GetFont(par, cursor.pos);
1097 int const asc = lyxfont::maxAscent(font);
1098 int const desc = lyxfont::maxDescent(font);
1099 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1101 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1102 cursor_visible = true;
1107 void InsetTabular::HideInsetCursor(BufferView * bv)
1109 if (cursor_visible) {
1110 bv->hideLockedInsetCursor();
1111 cursor_visible = false;
1113 // if (cursor_visible)
1114 // ToggleInsetCursor(bv);
1118 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1122 actcell = actrow = actcol = 0;
1123 int ly = tabular->GetDescentOfRow(actrow);
1125 // first search the right row
1126 while((ly < y) && (actrow < tabular->rows())) {
1127 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1128 tabular->GetAscentOfRow(actrow + 1) +
1129 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
1132 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1134 actcell = tabular->GetCellNumber(actrow, actcol);
1136 // now search the right column
1137 int lx = tabular->GetWidthOfColumn(actcell) -
1138 tabular->GetAdditionalWidth(actcell);
1140 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1141 for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
1142 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1143 tabular->GetAdditionalWidth(actcell - 1));
1145 // Jürgen, you should check that this is correct. (Lgb)
1146 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1147 lx += tabular->GetWidthOfColumn(actcell + 1)
1148 + tabular->GetAdditionalWidth(actcell);
1152 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1157 int InsetTabular::getCellXPos(int cell) const
1161 for (; !tabular->IsFirstCellInRow(c); --c)
1163 int lx = tabular->GetWidthOfColumn(cell);
1164 for (; c < cell; ++c) {
1165 lx += tabular->GetWidthOfColumn(c);
1167 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1171 void InsetTabular::resetPos(BufferView * bv) const
1175 actcol = tabular->column_of_cell(actcell);
1180 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1181 if (tabular->IsLastCellInRow(cell)) {
1182 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1183 tabular->GetAscentOfRow(actrow + 1) +
1184 tabular->GetAdditionalHeight(cell + 1));
1188 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1189 int new_x = getCellXPos(actcell);
1190 int old_x = cursor.x();
1193 // cursor.x(getCellXPos(actcell) + offset);
1194 if (((cursor.x() - offset) > 20) &&
1195 ((cursor.x()-offset+tabular->GetWidthOfColumn(actcell)) >
1196 (bv->workWidth()-20)))
1198 scroll(bv, -tabular->GetWidthOfColumn(actcell)-20);
1199 UpdateLocal(bv, FULL, false);
1200 } else if ((cursor.x() - offset) < 20) {
1201 scroll(bv, 20 - cursor.x() + offset);
1202 UpdateLocal(bv, FULL, false);
1203 } else if (scroll() && (top_x > 20) &&
1204 ((top_x+tabular->GetWidthOfTabular()) > (bv->workWidth()-20))) {
1205 scroll(bv, old_x - cursor.x());
1207 if ((!the_locking_inset ||
1208 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1209 (actcell != oldcell)) {
1210 InsetTabular * inset = const_cast<InsetTabular *>(this);
1211 bv->owner()->getDialogs()->updateTabular(inset);
1217 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1219 if (lock && !old_locking_inset) {
1220 if (ActivateCellInset(bv))
1223 bool moved = isRightToLeft(bv) ? movePrevCell(bv) : moveNextCell(bv);
1226 if (lock && ActivateCellInset(bv))
1230 return DISPATCHED_NOUPDATE;
1234 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1236 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1239 if (lock) { // behind the inset
1240 if (ActivateCellInset(bv, 0, 0, 0, true))
1244 return DISPATCHED_NOUPDATE;
1248 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1250 int const ocell = actcell;
1251 actcell = tabular->GetCellAbove(actcell);
1252 if (actcell == ocell) // we moved out of the inset
1258 if (old_locking_inset) {
1259 old_locking_inset->GetCursorPos(bv, x, y);
1260 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1262 if (ActivateCellInset(bv, x, 0))
1265 return DISPATCHED_NOUPDATE;
1269 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1271 int const ocell = actcell;
1272 actcell = tabular->GetCellBelow(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 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1292 if (isRightToLeft(bv)) {
1293 if (tabular->IsFirstCellInRow(actcell)) {
1294 int row = tabular->row_of_cell(actcell);
1295 if (row == tabular->rows() - 1)
1297 actcell = tabular->GetLastCellInRow(row);
1298 actcell = tabular->GetCellBelow(actcell);
1305 if (tabular->IsLastCell(actcell))
1310 bool rtl = tabular->GetCellInset(actcell)->par->
1311 isRightToLeftPar(bv->buffer()->params);
1312 ActivateCellInset(bv, 0, 0, 0, !rtl);
1319 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1321 if (isRightToLeft(bv)) {
1322 if (tabular->IsLastCellInRow(actcell)) {
1323 int row = tabular->row_of_cell(actcell);
1326 actcell = tabular->GetFirstCellInRow(row);
1327 actcell = tabular->GetCellAbove(actcell);
1329 if (tabular->IsLastCell(actcell))
1334 if (!actcell) // first cell
1339 bool rtl = tabular->GetCellInset(actcell)->par->
1340 isRightToLeftPar(bv->buffer()->params);
1341 ActivateCellInset(bv, 0, 0, 0, !rtl);
1348 bool InsetTabular::Delete()
1354 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1356 if (the_locking_inset)
1357 the_locking_inset->SetFont(bv, font, tall);
1361 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1363 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1366 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1367 string const tmp = tabularFeatures[i].feature;
1369 if (tmp == what.substr(0, tmp.length())) {
1370 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1371 //tabularFeatures[i].feature.length())) {
1372 action = tabularFeatures[i].action;
1376 if (action == LyXTabular::LAST_ACTION)
1380 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1381 TabularFeatures(bv, action, val);
1386 void InsetTabular::TabularFeatures(BufferView * bv,
1387 LyXTabular::Feature feature,
1388 string const & value)
1397 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1398 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1403 case LyXTabular::M_ALIGN_LEFT:
1404 case LyXTabular::ALIGN_LEFT:
1405 setAlign=LYX_ALIGN_LEFT;
1407 case LyXTabular::M_ALIGN_RIGHT:
1408 case LyXTabular::ALIGN_RIGHT:
1409 setAlign=LYX_ALIGN_RIGHT;
1411 case LyXTabular::M_ALIGN_CENTER:
1412 case LyXTabular::ALIGN_CENTER:
1413 setAlign=LYX_ALIGN_CENTER;
1415 case LyXTabular::M_VALIGN_TOP:
1416 case LyXTabular::VALIGN_TOP:
1417 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1419 case LyXTabular::M_VALIGN_BOTTOM:
1420 case LyXTabular::VALIGN_BOTTOM:
1421 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1423 case LyXTabular::M_VALIGN_CENTER:
1424 case LyXTabular::VALIGN_CENTER:
1425 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1430 if (hasSelection()) {
1431 sel_col_start = tabular->column_of_cell(sel_cell_start);
1432 sel_col_end = tabular->column_of_cell(sel_cell_end);
1433 if (sel_col_start > sel_col_end) {
1434 sel_col_end = sel_col_start;
1435 sel_col_start = tabular->column_of_cell(sel_cell_end);
1437 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1440 sel_row_start = tabular->row_of_cell(sel_cell_start);
1441 sel_row_end = tabular->row_of_cell(sel_cell_end);
1442 if (sel_row_start > sel_row_end) {
1443 //int tmp = sel_row_start;
1444 //sel_row_start = sel_row_end;
1445 //sel_row_end = tmp;
1446 swap(sel_row_start, sel_row_end);
1449 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1450 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1452 bv->text->SetUndo(bv->buffer(), Undo::FINISH,
1454 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1455 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1457 bv->text->cursor.par()->previous,
1458 bv->text->cursor.par()->next
1462 int row = tabular->row_of_cell(actcell);
1463 int column = tabular->column_of_cell(actcell);
1467 case LyXTabular::SET_PWIDTH:
1469 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1470 tabular->SetColumnPWidth(actcell,value);
1472 for (int i=0; i < tabular->rows(); ++i) {
1473 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1476 UpdateLocal(bv, INIT, true);
1480 case LyXTabular::SET_MPWIDTH:
1482 bool const update = (tabular->GetPWidth(actcell) != value);
1483 tabular->SetMColumnPWidth(actcell,value);
1485 for (int i=0; i < tabular->rows(); ++i) {
1486 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1489 UpdateLocal(bv, INIT, true);
1493 case LyXTabular::SET_SPECIAL_COLUMN:
1494 case LyXTabular::SET_SPECIAL_MULTI:
1495 tabular->SetAlignSpecial(actcell,value,feature);
1497 case LyXTabular::APPEND_ROW:
1498 // append the row into the tabular
1499 UnlockInsetInInset(bv, the_locking_inset);
1500 tabular->AppendRow(actcell);
1501 UpdateLocal(bv, INIT, true);
1503 case LyXTabular::APPEND_COLUMN:
1504 // append the column into the tabular
1505 UnlockInsetInInset(bv, the_locking_inset);
1506 tabular->AppendColumn(actcell);
1507 actcell = tabular->GetCellNumber(row, column);
1508 UpdateLocal(bv, INIT, true);
1510 case LyXTabular::DELETE_ROW:
1511 UnlockInsetInInset(bv, the_locking_inset);
1512 tabular->DeleteRow(tabular->row_of_cell(actcell));
1513 if ((row+1) > tabular->rows())
1515 actcell = tabular->GetCellNumber(row, column);
1517 UpdateLocal(bv, INIT, true);
1519 case LyXTabular::DELETE_COLUMN:
1520 UnlockInsetInInset(bv, the_locking_inset);
1521 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1522 if ((column+1) > tabular->columns())
1524 actcell = tabular->GetCellNumber(row, column);
1526 UpdateLocal(bv, INIT, true);
1528 case LyXTabular::M_TOGGLE_LINE_TOP:
1530 case LyXTabular::TOGGLE_LINE_TOP:
1531 lineSet = !tabular->TopLine(actcell, flag);
1532 for (i=sel_row_start; i<=sel_row_end; ++i)
1533 for (j=sel_col_start; j<=sel_col_end; ++j)
1534 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet, flag);
1535 UpdateLocal(bv, INIT, true);
1538 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1540 case LyXTabular::TOGGLE_LINE_BOTTOM:
1541 lineSet = !tabular->BottomLine(actcell, flag);
1542 for (i=sel_row_start; i<=sel_row_end; ++i)
1543 for (j=sel_col_start; j<=sel_col_end; ++j)
1544 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet,
1546 UpdateLocal(bv, INIT, true);
1549 case LyXTabular::M_TOGGLE_LINE_LEFT:
1551 case LyXTabular::TOGGLE_LINE_LEFT:
1552 lineSet = !tabular->LeftLine(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->SetLeftLine(tabular->GetCellNumber(i,j),lineSet,
1557 UpdateLocal(bv, INIT, true);
1560 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1562 case LyXTabular::TOGGLE_LINE_RIGHT:
1563 lineSet = !tabular->RightLine(actcell, flag);
1564 for (i=sel_row_start; i<=sel_row_end; ++i)
1565 for (j=sel_col_start; j<=sel_col_end; ++j)
1566 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet,
1568 UpdateLocal(bv, INIT, true);
1570 case LyXTabular::M_ALIGN_LEFT:
1571 case LyXTabular::M_ALIGN_RIGHT:
1572 case LyXTabular::M_ALIGN_CENTER:
1574 case LyXTabular::ALIGN_LEFT:
1575 case LyXTabular::ALIGN_RIGHT:
1576 case LyXTabular::ALIGN_CENTER:
1577 for (i = sel_row_start; i <= sel_row_end; ++i)
1578 for (j = sel_col_start; j <= sel_col_end; ++j)
1579 tabular->SetAlignment(tabular->GetCellNumber(i, j), setAlign,
1581 UpdateLocal(bv, INIT, true);
1583 case LyXTabular::M_VALIGN_TOP:
1584 case LyXTabular::M_VALIGN_BOTTOM:
1585 case LyXTabular::M_VALIGN_CENTER:
1587 case LyXTabular::VALIGN_TOP:
1588 case LyXTabular::VALIGN_BOTTOM:
1589 case LyXTabular::VALIGN_CENTER:
1590 for (i = sel_row_start; i <= sel_row_end; ++i)
1591 for (j = sel_col_start; j <= sel_col_end; ++j)
1592 tabular->SetVAlignment(tabular->GetCellNumber(i, j),
1594 UpdateLocal(bv, INIT, true);
1596 case LyXTabular::MULTICOLUMN:
1598 if (sel_row_start != sel_row_end) {
1599 WriteAlert(_("Impossible Operation!"),
1600 _("Multicolumns can only be horizontally."),
1604 // just multicol for one Single Cell
1605 if (!hasSelection()) {
1606 // check wether we are completly in a multicol
1607 if (tabular->IsMultiColumn(actcell)) {
1608 tabular->UnsetMultiColumn(actcell);
1609 UpdateLocal(bv, INIT, true);
1611 tabular->SetMultiColumn(actcell, 1);
1612 UpdateLocal(bv, CELL, true);
1616 // we have a selection so this means we just add all this
1617 // cells to form a multicolumn cell
1621 if (sel_cell_start > sel_cell_end) {
1622 s_start = sel_cell_end;
1623 s_end = sel_cell_start;
1625 s_start = sel_cell_start;
1626 s_end = sel_cell_end;
1628 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1630 sel_cell_end = sel_cell_start;
1631 UpdateLocal(bv, INIT, true);
1634 case LyXTabular::SET_ALL_LINES:
1636 case LyXTabular::UNSET_ALL_LINES:
1637 for (i=sel_row_start; i<=sel_row_end; ++i)
1638 for (j=sel_col_start; j<=sel_col_end; ++j)
1639 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1640 UpdateLocal(bv, INIT, true);
1642 case LyXTabular::SET_LONGTABULAR:
1643 tabular->SetLongTabular(true);
1644 UpdateLocal(bv, INIT, true); // because this toggles displayed
1646 case LyXTabular::UNSET_LONGTABULAR:
1647 tabular->SetLongTabular(false);
1648 UpdateLocal(bv, INIT, true); // because this toggles displayed
1650 case LyXTabular::SET_ROTATE_TABULAR:
1651 tabular->SetRotateTabular(true);
1653 case LyXTabular::UNSET_ROTATE_TABULAR:
1654 tabular->SetRotateTabular(false);
1656 case LyXTabular::SET_ROTATE_CELL:
1657 for (i=sel_row_start; i<=sel_row_end; ++i)
1658 for (j=sel_col_start; j<=sel_col_end; ++j)
1659 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1661 case LyXTabular::UNSET_ROTATE_CELL:
1662 for (i = sel_row_start; i <= sel_row_end; ++i)
1663 for (j = sel_col_start; j <= sel_col_end; ++j)
1664 tabular->SetRotateCell(tabular->GetCellNumber(i, j), false);
1666 case LyXTabular::SET_USEBOX:
1668 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1669 if (val == tabular->GetUsebox(actcell))
1670 val = LyXTabular::BOX_NONE;
1671 for (i = sel_row_start; i <= sel_row_end; ++i)
1672 for (j = sel_col_start; j <= sel_col_end; ++j)
1673 tabular->SetUsebox(tabular->GetCellNumber(i, j), val);
1676 case LyXTabular::SET_LTFIRSTHEAD:
1677 tabular->SetLTHead(actcell, true);
1679 case LyXTabular::SET_LTHEAD:
1680 tabular->SetLTHead(actcell, false);
1682 case LyXTabular::SET_LTFOOT:
1683 tabular->SetLTFoot(actcell, false);
1685 case LyXTabular::SET_LTLASTFOOT:
1686 tabular->SetLTFoot(actcell, true);
1688 case LyXTabular::SET_LTNEWPAGE:
1689 what = !tabular->GetLTNewPage(actcell);
1690 tabular->SetLTNewPage(actcell, what);
1692 // dummy stuff just to avoid warnings
1693 case LyXTabular::LAST_ACTION:
1699 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1702 UpdatableInset * inset =
1703 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1704 LyXFont font(LyXFont::ALL_SANE);
1706 x = inset->x() + inset->width(bv, font);
1707 y = inset->descent(bv, font);
1709 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1710 //inset_y = cursor.y();
1711 inset->Edit(bv, x, y, button);
1712 if (!the_locking_inset)
1714 UpdateLocal(bv, CELL, false);
1715 return (the_locking_inset != 0);
1719 bool InsetTabular::ActivateCellInsetAbs(BufferView * bv, int x, int y,
1722 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1723 inset_y = cursor.y();
1724 return ActivateCellInset(bv, x - inset_x, y - inset_y, button);
1728 bool InsetTabular::InsetHit(BufferView *, int x, int) const
1730 return x + top_x > cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1734 // This returns paperWidth() if the cell-width is unlimited or the width
1735 // in pixels if we have a pwidth for this cell.
1736 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1738 string const s = tabular->GetPWidth(cell);
1742 return VSpace(s).inPixels(0, 0);
1746 int InsetTabular::getMaxWidth(Painter & pain,
1747 UpdatableInset const * inset) const
1749 int const n = tabular->GetNumberOfCells();
1751 for (; cell < n; ++cell) {
1752 if (tabular->GetCellInset(cell) == inset)
1757 int w = GetMaxWidthOfCell(pain, cell);
1759 // because the inset then subtracts it's top_x and owner->x()
1760 w += (inset->x() - top_x);
1765 void InsetTabular::resizeLyXText(BufferView *) const
1771 LyXText * InsetTabular::getLyXText(BufferView const * bv) const
1773 if (the_locking_inset)
1774 return the_locking_inset->getLyXText(bv);
1775 return Inset::getLyXText(bv);
1779 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1781 if (the_locking_inset) {
1782 InsetTabular * i = static_cast<InsetTabular *>
1783 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1785 i->OpenLayoutDialog(bv);
1789 bv->owner()->getDialogs()->showTabular(const_cast<InsetTabular *>(this));
1793 // functions returns:
1797 // 3 ... toggled off
1799 LyXFunc::func_status InsetTabular::getStatus(string const & what) const
1801 int action = LyXTabular::LAST_ACTION;
1802 LyXFunc::func_status status = LyXFunc::OK;
1805 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1806 string const tmp = tabularFeatures[i].feature;
1807 if (tmp == what.substr(0, tmp.length())) {
1808 //if (!strncmp(tabularFeatures[i].feature.c_str(), what.c_str(),
1809 // tabularFeatures[i].feature.length())) {
1810 action = tabularFeatures[i].action;
1814 if (action == LyXTabular::LAST_ACTION)
1815 return LyXFunc::Unknown;
1817 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
1819 int sel_row_start, sel_row_end;
1823 if (hasSelection()) {
1824 sel_row_start = tabular->row_of_cell(sel_cell_start);
1825 sel_row_end = tabular->row_of_cell(sel_cell_end);
1826 if (sel_row_start > sel_row_end) {
1827 //int tmp = sel_row_start;
1828 //sel_row_start = sel_row_end;
1829 //sel_row_end = tmp;
1830 swap(sel_row_start, sel_row_end);
1833 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1837 case LyXTabular::SET_PWIDTH:
1838 case LyXTabular::SET_MPWIDTH:
1839 case LyXTabular::SET_SPECIAL_COLUMN:
1840 case LyXTabular::SET_SPECIAL_MULTI:
1841 status |= LyXFunc::Disabled;
1844 case LyXTabular::APPEND_ROW:
1845 case LyXTabular::APPEND_COLUMN:
1846 case LyXTabular::DELETE_ROW:
1847 case LyXTabular::DELETE_COLUMN:
1848 case LyXTabular::SET_ALL_LINES:
1849 case LyXTabular::UNSET_ALL_LINES:
1850 status |= LyXFunc::OK;
1853 case LyXTabular::MULTICOLUMN:
1854 if (tabular->IsMultiColumn(actcell))
1855 status |= LyXFunc::ToggleOn;
1857 status |= LyXFunc::ToggleOff;
1859 case LyXTabular::M_TOGGLE_LINE_TOP:
1861 case LyXTabular::TOGGLE_LINE_TOP:
1862 if (tabular->TopLine(actcell, flag))
1863 status |= LyXFunc::ToggleOn;
1865 status |= LyXFunc::ToggleOff;
1867 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1869 case LyXTabular::TOGGLE_LINE_BOTTOM:
1870 if (tabular->BottomLine(actcell, flag))
1871 status |= LyXFunc::ToggleOn;
1873 status |= LyXFunc::ToggleOff;
1875 case LyXTabular::M_TOGGLE_LINE_LEFT:
1877 case LyXTabular::TOGGLE_LINE_LEFT:
1878 if (tabular->LeftLine(actcell, flag))
1879 status |= LyXFunc::ToggleOn;
1881 status |= LyXFunc::ToggleOff;
1883 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1885 case LyXTabular::TOGGLE_LINE_RIGHT:
1886 if (tabular->RightLine(actcell, flag))
1887 status |= LyXFunc::ToggleOn;
1889 status |= LyXFunc::ToggleOff;
1891 case LyXTabular::M_ALIGN_LEFT:
1893 case LyXTabular::ALIGN_LEFT:
1894 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
1895 status |= LyXFunc::ToggleOn;
1897 status |= LyXFunc::ToggleOff;
1899 case LyXTabular::M_ALIGN_RIGHT:
1901 case LyXTabular::ALIGN_RIGHT:
1902 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
1903 status |= LyXFunc::ToggleOn;
1905 status |= LyXFunc::ToggleOff;
1907 case LyXTabular::M_ALIGN_CENTER:
1909 case LyXTabular::ALIGN_CENTER:
1910 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
1911 status |= LyXFunc::ToggleOn;
1913 status |= LyXFunc::ToggleOff;
1915 case LyXTabular::M_VALIGN_TOP:
1917 case LyXTabular::VALIGN_TOP:
1918 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
1919 status |= LyXFunc::ToggleOn;
1921 status |= LyXFunc::ToggleOff;
1923 case LyXTabular::M_VALIGN_BOTTOM:
1925 case LyXTabular::VALIGN_BOTTOM:
1926 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
1927 status |= LyXFunc::ToggleOn;
1929 status |= LyXFunc::ToggleOff;
1931 case LyXTabular::M_VALIGN_CENTER:
1933 case LyXTabular::VALIGN_CENTER:
1934 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
1935 status |= LyXFunc::ToggleOn;
1937 status |= LyXFunc::ToggleOff;
1939 case LyXTabular::SET_LONGTABULAR:
1940 if (tabular->IsLongTabular())
1941 status |= LyXFunc::ToggleOn;
1943 status |= LyXFunc::ToggleOff;
1945 case LyXTabular::UNSET_LONGTABULAR:
1946 if (!tabular->IsLongTabular())
1947 status |= LyXFunc::ToggleOn;
1949 status |= LyXFunc::ToggleOff;
1951 case LyXTabular::SET_ROTATE_TABULAR:
1952 if (tabular->GetRotateTabular())
1953 status |= LyXFunc::ToggleOn;
1955 status |= LyXFunc::ToggleOff;
1957 case LyXTabular::UNSET_ROTATE_TABULAR:
1958 if (!tabular->GetRotateTabular())
1959 status |= LyXFunc::ToggleOn;
1961 status |= LyXFunc::ToggleOff;
1963 case LyXTabular::SET_ROTATE_CELL:
1964 if (tabular->GetRotateCell(actcell))
1965 status |= LyXFunc::ToggleOn;
1967 status |= LyXFunc::ToggleOff;
1969 case LyXTabular::UNSET_ROTATE_CELL:
1970 if (!tabular->GetRotateCell(actcell))
1971 status |= LyXFunc::ToggleOn;
1973 status |= LyXFunc::ToggleOff;
1975 case LyXTabular::SET_USEBOX:
1976 if (strToInt(argument) == tabular->GetUsebox(actcell))
1977 status |= LyXFunc::ToggleOn;
1979 status |= LyXFunc::ToggleOff;
1981 case LyXTabular::SET_LTFIRSTHEAD:
1982 if (tabular->GetRowOfLTHead(actcell, dummy))
1983 status |= LyXFunc::ToggleOn;
1985 status |= LyXFunc::ToggleOff;
1987 case LyXTabular::SET_LTHEAD:
1988 if (tabular->GetRowOfLTHead(actcell, dummy))
1989 status |= LyXFunc::ToggleOn;
1991 status |= LyXFunc::ToggleOff;
1993 case LyXTabular::SET_LTFOOT:
1994 if (tabular->GetRowOfLTFoot(actcell, dummy))
1995 status |= LyXFunc::ToggleOn;
1997 status |= LyXFunc::ToggleOff;
1999 case LyXTabular::SET_LTLASTFOOT:
2000 if (tabular->GetRowOfLTFoot(actcell, dummy))
2001 status |= LyXFunc::ToggleOn;
2003 status |= LyXFunc::ToggleOff;
2005 case LyXTabular::SET_LTNEWPAGE:
2006 if (tabular->GetLTNewPage(actcell))
2007 status |= LyXFunc::ToggleOn;
2009 status |= LyXFunc::ToggleOff;
2012 status = LyXFunc::Disabled;
2019 bool InsetTabular::copySelection(BufferView * bv)
2021 if (!hasSelection())
2023 delete paste_tabular;
2025 int sel_col_start, sel_col_end;
2026 int sel_row_start, sel_row_end;
2028 sel_col_start = tabular->column_of_cell(sel_cell_start);
2029 sel_col_end = tabular->column_of_cell(sel_cell_end);
2030 if (sel_col_start > sel_col_end) {
2031 sel_col_start = sel_col_end;
2032 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2034 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2036 int columns = sel_col_end - sel_col_start + 1;
2038 sel_row_start = tabular->row_of_cell(sel_cell_start);
2039 sel_row_end = tabular->row_of_cell(sel_cell_end);
2040 if (sel_row_start > sel_row_end) {
2041 //int tmp tmp = sel_row_start;
2042 //sel_row_start = sel_row_end;
2043 //sel_row_end = tmp;
2044 swap(sel_row_start, sel_row_end);
2046 int rows = sel_row_end - sel_row_start + 1;
2048 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2050 for (i=0; i < sel_row_start; ++i)
2051 paste_tabular->DeleteRow(0);
2052 while(paste_tabular->rows() > rows)
2053 paste_tabular->DeleteRow(rows);
2054 paste_tabular->SetTopLine(0, true, true);
2055 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2057 for (i=0; i < sel_col_start; ++i)
2058 paste_tabular->DeleteColumn(0);
2059 while(paste_tabular->columns() > columns)
2060 paste_tabular->DeleteColumn(columns);
2061 paste_tabular->SetLeftLine(0, true, true);
2062 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),true, true);
2065 paste_tabular->Ascii(bv->buffer(), sstr);
2066 bv->stuffClipboard(sstr.str().c_str());
2071 bool InsetTabular::pasteSelection(BufferView * bv)
2076 for (int r1 = 0, r2 = actrow;
2077 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2080 for(int c1 = 0, c2 = actcol;
2081 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2084 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2085 tabular->IsPartOfMultiColumn(r2,c2))
2087 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2091 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2095 int n1 = paste_tabular->GetCellNumber(r1, c1);
2096 int n2 = tabular->GetCellNumber(r2, c2);
2097 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2098 tabular->GetCellInset(n2)->setOwner(this);
2099 tabular->GetCellInset(n2)->deleteLyXText(bv);
2106 bool InsetTabular::cutSelection()
2108 if (!hasSelection())
2111 int sel_col_start, sel_col_end;
2112 int sel_row_start, sel_row_end;
2114 sel_col_start = tabular->column_of_cell(sel_cell_start);
2115 sel_col_end = tabular->column_of_cell(sel_cell_end);
2116 if (sel_col_start > sel_col_end) {
2117 sel_col_start = sel_col_end;
2118 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2120 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2122 sel_row_start = tabular->row_of_cell(sel_cell_start);
2123 sel_row_end = tabular->row_of_cell(sel_cell_end);
2124 if (sel_row_start > sel_row_end) {
2125 //int tmp = sel_row_start;
2126 //sel_row_start = sel_row_end;
2127 //sel_row_end = tmp;
2128 swap(sel_row_start, sel_row_end);
2130 if (sel_cell_start > sel_cell_end) {
2131 //int tmp = sel_cell_start;
2132 //sel_cell_start = sel_cell_end;
2133 //sel_cell_end = tmp;
2134 swap(sel_cell_start, sel_cell_end);
2136 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2137 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2138 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2144 bool InsetTabular::isRightToLeft(BufferView *bv )
2146 return bv->getParentLanguage(this)->RightToLeft();