1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
20 #pragma implementation
23 #include "insettabular.h"
26 #include "commandtags.h"
29 #include "LaTeXFeatures.h"
33 #include "lyx_gui_misc.h"
35 #include "insets/insettext.h"
36 #include "frontends/Dialogs.h"
41 #include "BufferView.h"
52 const int ADD_TO_HEIGHT = 2;
53 const int ADD_TO_TABULAR_WIDTH = 2;
55 LyXTabular * paste_tabular = 0;
58 struct tabular_features {
59 LyXTabular::Feature action;
63 //tabular_features * tabularFeatures = 0;
65 tabular_features tabularFeatures[] =
67 { LyXTabular::APPEND_ROW, "append-row" },
68 { LyXTabular::APPEND_COLUMN, "append-column" },
69 { LyXTabular::DELETE_ROW, "delete-row" },
70 { LyXTabular::DELETE_COLUMN, "delete-column" },
71 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
72 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
73 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
74 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
75 { LyXTabular::ALIGN_LEFT, "align-left" },
76 { LyXTabular::ALIGN_RIGHT, "align-right" },
77 { LyXTabular::ALIGN_CENTER, "align-center" },
78 { LyXTabular::VALIGN_TOP, "valign-top" },
79 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
80 { LyXTabular::VALIGN_CENTER, "valign-center" },
81 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
82 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
83 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
84 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
85 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
86 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
87 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
88 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
89 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
90 { LyXTabular::M_VALIGN_CENTER, "m-valign-center" },
91 { LyXTabular::MULTICOLUMN, "multicolumn" },
92 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
93 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
94 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
95 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
96 { LyXTabular::SET_PWIDTH, "set-pwidth" },
97 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
98 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
99 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
100 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
101 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
102 { LyXTabular::SET_USEBOX, "set-usebox" },
103 { LyXTabular::SET_LTHEAD, "set-lthead" },
104 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
105 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
106 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
107 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
108 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
109 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
110 { LyXTabular::LAST_ACTION, "" }
116 bool InsetTabular::hasPasteBuffer() const
118 return (paste_tabular != 0);
122 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
129 tabular.reset(new LyXTabular(this, rows,columns));
130 // for now make it always display as display() inset
132 the_locking_inset = 0;
133 locked = no_selection = false;
135 actrow = actcell = 0;
141 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
144 tabular.reset(new LyXTabular(this, *(tab.tabular)));
145 the_locking_inset = 0;
146 locked = no_selection = false;
148 actrow = actcell = 0;
149 sel_cell_start = sel_cell_end = 0;
154 InsetTabular::~InsetTabular()
161 Inset * InsetTabular::Clone(Buffer const & buf) const
163 InsetTabular * t = new InsetTabular(*this, buf);
165 //t->tabular = tabular->Clone(t);
166 t->tabular.reset(tabular->Clone(t));
171 void InsetTabular::Write(Buffer const * buf, ostream & os) const
173 os << " Tabular" << endl;
174 tabular->Write(buf, os);
178 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
180 bool const old_format = (lex.GetString() == "\\LyXTable");
184 //tabular = new LyXTabular(buf, this, lex);
185 tabular.reset(new LyXTabular(buf, this, lex));
193 string token = lex.GetString();
194 while (lex.IsOK() && (token != "\\end_inset")) {
196 token = lex.GetString();
198 if (token != "\\end_inset") {
199 lex.printError("Missing \\end_inset at this point. "
205 int InsetTabular::ascent(BufferView *, LyXFont const &) const
207 return tabular->GetAscentOfRow(0);
211 int InsetTabular::descent(BufferView *, LyXFont const &) const
213 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
217 int InsetTabular::width(BufferView *, LyXFont const &) const
219 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
223 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
224 float & x, bool cleared) const
232 if (need_update == INIT) {
233 if (calculate_dimensions_of_cells(bv, font, true))
234 bv->text->status = LyXText::CHANGED_IN_DRAW;
239 Painter & pain = bv->painter();
245 UpdatableInset::draw(bv, font, baseline, x, cleared);
248 x += static_cast<float>(scroll());
250 if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
251 (top_x != int(x)) || (top_baseline != baseline))) {
252 int h = ascent(bv, font) + descent(bv, font);
253 int const tx = display() || !owner() ? 0 : top_x;
254 int w = tx ? width(bv, font) : pain.paperWidth();
255 int ty = baseline - ascent(bv, font);
259 if ((ty + h) > pain.paperHeight())
260 h = pain.paperHeight();
261 if ((top_x + w) > pain.paperWidth())
262 w = pain.paperWidth();
263 pain.fillRectangle(tx, ty, w, h);
268 top_baseline = baseline;
269 x += ADD_TO_TABULAR_WIDTH;
273 first_visible_cell = -1;
274 for (i = 0; i < tabular->rows(); ++i) {
276 cell = tabular->GetCellNumber(i, 0);
277 if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
278 (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
280 baseline += tabular->GetDescentOfRow(i) +
281 tabular->GetAscentOfRow(i + 1) +
282 tabular->GetAdditionalHeight(i + 1);
285 for (j = 0; j < tabular->columns(); ++j) {
286 if (nx > bv->workWidth())
288 if (tabular->IsPartOfMultiColumn(i, j))
290 cx = nx + tabular->GetBeginningOfTextInCell(cell);
291 if (first_visible_cell < 0)
292 first_visible_cell = cell;
294 DrawCellSelection(pain, nx, baseline, i, j, cell);
296 tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
298 DrawCellLines(pain, nx, baseline, i, cell);
299 nx += tabular->GetWidthOfColumn(cell);
302 baseline += tabular->GetDescentOfRow(i) +
303 tabular->GetAscentOfRow(i + 1) +
304 tabular->GetAdditionalHeight(i + 1);
306 } else if (need_update == CELL) {
309 if (the_locking_inset &&
310 tabular->GetCellInset(actcell) != the_locking_inset)
312 #warning Jürgen, why is this?
313 Inset * inset = tabular->GetCellInset(cell);
315 inset != the_locking_inset && i < tabular->rows();
318 inset != the_locking_inset
319 && j < tabular->columns();
321 if (tabular->IsPartOfMultiColumn(i, j))
323 nx += tabular->GetWidthOfColumn(cell);
325 inset = tabular->GetCellInset(cell);
327 if (tabular->row_of_cell(cell) > i) {
329 baseline += tabular->GetDescentOfRow(i) +
330 tabular->GetAscentOfRow(i + 1) +
331 tabular->GetAdditionalHeight(i + 1);
335 // copute baseline for actual row
336 for (i = 0; i < actrow; ++i) {
337 baseline += tabular->GetDescentOfRow(i) +
338 tabular->GetAscentOfRow(i + 1) +
339 tabular->GetAdditionalHeight(i + 1);
341 // now compute the right x position
342 cell = tabular->GetCellNumber(actrow, 0);
343 for (j = 0; (cell < actcell) && (j < tabular->columns()); ++j) {
344 if (tabular->IsPartOfMultiColumn(actrow, j))
346 nx += tabular->GetWidthOfColumn(cell);
350 i = tabular->row_of_cell(cell);
351 if (the_locking_inset != tabular->GetCellInset(cell)) {
352 lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
355 float dx = nx + tabular->GetBeginningOfTextInCell(cell);
357 //cx = dx = nx + tabular->GetBeginningOfTextInCell(cell);
358 tabular->GetCellInset(cell)->draw(bv, font, baseline, dx, false);
360 if (bv->text->status == LyXText::CHANGED_IN_DRAW)
363 // clear only if we didn't have a change
364 if (need_update == CELL) {
365 // clear before the inset
368 baseline - tabular->GetAscentOfRow(i) + 1,
370 tabular->GetAscentOfRow(i) +
371 tabular->GetDescentOfRow(i) - 1);
372 // clear behind the inset
374 int(cx + the_locking_inset->width(bv,font) + 1),
375 baseline - tabular->GetAscentOfRow(i) + 1,
376 tabular->GetWidthOfColumn(cell) -
377 tabular->GetBeginningOfTextInCell(cell) -
378 the_locking_inset->width(bv,font) -
379 tabular->GetAdditionalWidth(cell) - 1,
380 tabular->GetAscentOfRow(i) +
381 tabular->GetDescentOfRow(i) - 1);
384 x -= ADD_TO_TABULAR_WIDTH;
385 x += width(bv, font);
386 if (bv->text->status == LyXText::CHANGED_IN_DRAW) {
388 for(Inset * inset=owner(); inset; ++i)
389 inset = inset->owner();
390 if (calculate_dimensions_of_cells(bv, font, false))
398 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
399 int row, int cell) const
401 int x2 = x + tabular->GetWidthOfColumn(cell);
404 if (!tabular->TopAlreadyDrawed(cell)) {
405 on_off = !tabular->TopLine(cell);
406 pain.line(x, baseline - tabular->GetAscentOfRow(row),
407 x2, baseline - tabular->GetAscentOfRow(row),
408 on_off ? LColor::tabularonoffline : LColor::tabularline,
409 on_off ? Painter::line_onoffdash : Painter::line_solid);
411 on_off = !tabular->BottomLine(cell);
412 pain.line(x,baseline + tabular->GetDescentOfRow(row),
413 x2, baseline + tabular->GetDescentOfRow(row),
414 on_off ? LColor::tabularonoffline : LColor::tabularline,
415 on_off ? Painter::line_onoffdash : Painter::line_solid);
416 if (!tabular->LeftAlreadyDrawed(cell)) {
417 on_off = !tabular->LeftLine(cell);
418 pain.line(x, baseline - tabular->GetAscentOfRow(row),
419 x, baseline + tabular->GetDescentOfRow(row),
420 on_off ? LColor::tabularonoffline : LColor::tabularline,
421 on_off ? Painter::line_onoffdash : Painter::line_solid);
423 on_off = !tabular->RightLine(cell);
424 pain.line(x2 - tabular->GetAdditionalWidth(cell),
425 baseline - tabular->GetAscentOfRow(row),
426 x2 - tabular->GetAdditionalWidth(cell),
427 baseline + tabular->GetDescentOfRow(row),
428 on_off ? LColor::tabularonoffline : LColor::tabularline,
429 on_off ? Painter::line_onoffdash : Painter::line_solid);
433 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
434 int row, int column, int cell) const
436 int cs = tabular->column_of_cell(sel_cell_start);
437 int ce = tabular->column_of_cell(sel_cell_end);
440 cs = tabular->column_of_cell(sel_cell_end);
442 ce = tabular->right_column_of_cell(sel_cell_end);
445 int rs = tabular->row_of_cell(sel_cell_start);
446 int re = tabular->row_of_cell(sel_cell_end);
447 if (rs > re) swap(rs, re);
449 if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
450 int w = tabular->GetWidthOfColumn(cell);
451 int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
452 pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
453 w, h, LColor::selection);
458 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
462 calculate_dimensions_of_cells(bv, font, true);
464 owner()->update(bv, font, true);
467 if (the_locking_inset)
468 the_locking_inset->update(bv, font, reinit);
470 switch (need_update) {
474 if (calculate_dimensions_of_cells(bv, font, false))
486 string const InsetTabular::EditMessage() const
488 return _("Opened Tabular Inset");
492 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
494 UpdatableInset::Edit(bv, x, y, button);
496 if (!bv->lockInset(this)) {
497 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
501 the_locking_inset = 0;
505 sel_cell_start = sel_cell_end = actcell;
506 bv->text->finishUndo();
507 if (InsetHit(bv, x, y) && (button != 3)) {
508 ActivateCellInsetAbs(bv, x, y, button);
510 // UpdateLocal(bv, NONE, false);
511 // bv->getOwner()->getPopups().updateFormTabular();
515 void InsetTabular::InsetUnlock(BufferView * bv)
517 if (the_locking_inset) {
518 the_locking_inset->InsetUnlock(bv);
519 the_locking_inset = 0;
522 no_selection = false;
525 if (scroll(false) || hasSelection()) {
526 sel_cell_start = sel_cell_end = 0;
530 UpdateLocal(bv, FULL, false);
535 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
536 bool mark_dirty) const
538 if (need_update < what) // only set this if it has greater update
540 if ((what == INIT) && hasSelection())
543 if (need_update != NONE) {
544 bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
545 if (locked) // && (what != NONE))
551 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
553 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset("
558 if (inset == tabular->GetCellInset(actcell)) {
559 lyxerr[Debug::INSETS] << "OK" << endl;
560 the_locking_inset = tabular->GetCellInset(actcell);
562 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
563 inset_y = cursor.y();
565 } else if (the_locking_inset && (the_locking_inset == inset)) {
566 lyxerr[Debug::INSETS] << "OK" << endl;
568 inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
569 inset_y = cursor.y();
570 } else if (the_locking_inset) {
571 lyxerr[Debug::INSETS] << "MAYBE" << endl;
572 return the_locking_inset->LockInsetInInset(bv, inset);
574 lyxerr[Debug::INSETS] << "NOT OK" << endl;
579 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
582 if (!the_locking_inset)
584 if (the_locking_inset == inset) {
585 the_locking_inset->InsetUnlock(bv);
586 the_locking_inset = 0;
588 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
594 UpdateLocal(bv, CELL, false);
595 ShowInsetCursor(bv, false);
598 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
599 if (inset->LyxCode() == TABULAR_CODE &&
600 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) {
601 bv->owner()->getDialogs()->updateTabular(this);
610 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
612 if (!the_locking_inset)
614 if (the_locking_inset != inset) {
615 if (!the_locking_inset->UpdateInsetInInset(bv, inset))
618 UpdateLocal(bv, CELL, false);
623 unsigned int InsetTabular::InsetInInsetY()
625 if (!the_locking_inset)
628 return inset_y + the_locking_inset->InsetInInsetY();
632 UpdatableInset * InsetTabular::GetLockingInset()
634 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
638 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
642 if (the_locking_inset)
643 return the_locking_inset->GetFirstLockingInsetOfType(c);
648 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
650 if (the_locking_inset)
651 return the_locking_inset->InsertInset(bv, inset);
656 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
658 if (hasSelection() && (button == 3))
661 if (hasSelection()) {
663 UpdateLocal(bv, SELECTION, false);
666 no_selection = false;
668 int const ocell = actcell;
669 int const orow = actrow;
674 UpdateLocal(bv, NONE, false);
675 sel_cell_start = sel_cell_end = actcell;
677 if ((ocell != actcell) && the_locking_inset) {
678 the_locking_inset->InsetUnlock(bv);
679 the_locking_inset = 0;
685 bool const inset_hit = InsetHit(bv, x, y);
687 if ((ocell == actcell) && the_locking_inset && inset_hit) {
689 the_locking_inset->InsetButtonPress(bv,
690 x - inset_x, y - inset_y,
693 } else if (the_locking_inset) {
694 the_locking_inset->InsetUnlock(bv);
696 the_locking_inset = 0;
698 LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph");
701 if (inset_hit && bv->theLockingInset()) {
702 if (ActivateCellInsetAbs(bv, x, y, button))
703 the_locking_inset->InsetButtonPress(bv,
713 void InsetTabular::InsetButtonRelease(BufferView * bv,
714 int x, int y, int button)
717 if (the_locking_inset) {
719 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
720 i->InsetButtonRelease(bv, x, y, button);
724 bv->owner()->getDialogs()->showTabular(this);
727 if (the_locking_inset) {
728 the_locking_inset->InsetButtonRelease(bv,
729 x - inset_x, y - inset_y,
733 no_selection = false;
737 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
739 if (the_locking_inset) {
740 the_locking_inset->InsetMotionNotify(bv,
748 int const old_cell = actcell;
751 sel_cell_end = actcell;
752 if (sel_cell_end != old_cell)
753 UpdateLocal(bv, SELECTION, false);
756 no_selection = false;
760 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
762 if (the_locking_inset) {
763 the_locking_inset->InsetKeyPress(xke);
769 UpdatableInset::RESULT
770 InsetTabular::LocalDispatch(BufferView * bv,
774 // We need to save the value of the_locking_inset as the call to
775 // the_locking_inset->LocalDispatch might unlock it.
776 old_locking_inset = the_locking_inset;
777 no_selection = false;
778 UpdatableInset::RESULT result =
779 UpdatableInset::LocalDispatch(bv, action, arg);
780 if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
785 if ((action < 0) && arg.empty())
788 bool hs = hasSelection();
791 // this one have priority over the locked InsetText!
796 if (GetFirstLockingInsetOfType(Inset::TABULAR_CODE) != this)
799 if (the_locking_inset) {
800 UnlockInsetInInset(bv, the_locking_inset);
801 the_locking_inset = 0;
803 if (action == LFUN_TAB)
804 moveNextCell(bv, old_locking_inset != 0);
806 movePrevCell(bv, old_locking_inset != 0);
807 sel_cell_start = sel_cell_end = actcell;
809 UpdateLocal(bv, SELECTION, false);
810 if (!the_locking_inset) {
812 return DISPATCHED_NOUPDATE;
816 // this to avoid compiler warnings.
821 if (the_locking_inset) {
822 result=the_locking_inset->LocalDispatch(bv, action, arg);
823 if (result == DISPATCHED_NOUPDATE) {
826 if (sc != scroll()) { // inset has been scrolled
827 the_locking_inset->ToggleInsetCursor(bv);
828 UpdateLocal(bv, FULL, false);
829 the_locking_inset->ToggleInsetCursor(bv);
832 } else if (result == DISPATCHED) {
833 the_locking_inset->ToggleInsetCursor(bv);
834 UpdateLocal(bv, CELL, false);
835 the_locking_inset->ToggleInsetCursor(bv);
837 } else if (result == FINISHED) {
844 // --- Cursor Movements ----------------------------------
846 if (tabular->IsLastCellInRow(actcell))
848 moveRight(bv, false);
849 sel_cell_end = actcell;
850 UpdateLocal(bv, SELECTION, false);
853 result = moveRight(bv);
854 sel_cell_start = sel_cell_end = actcell;
856 UpdateLocal(bv, SELECTION, false);
859 if (tabular->IsFirstCellInRow(actcell))
862 sel_cell_end = actcell;
863 UpdateLocal(bv, SELECTION, false);
866 result = moveLeft(bv);
867 sel_cell_start = sel_cell_end = actcell;
869 UpdateLocal(bv, SELECTION, false);
873 int const ocell = actcell;
875 if ((ocell == sel_cell_end) ||
876 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
877 sel_cell_end = tabular->GetCellBelow(sel_cell_end);
879 sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
880 UpdateLocal(bv, SELECTION, false);
884 result = moveDown(bv, old_locking_inset != 0);
885 sel_cell_start = sel_cell_end = actcell;
887 UpdateLocal(bv, SELECTION, false);
891 int const ocell = actcell;
893 if ((ocell == sel_cell_end) ||
894 (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
895 sel_cell_end = tabular->GetCellAbove(sel_cell_end);
897 sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
898 UpdateLocal(bv, SELECTION, false);
902 result = moveUp(bv, old_locking_inset != 0);
903 sel_cell_start = sel_cell_end = actcell;
905 UpdateLocal(bv, SELECTION, false);
909 if (the_locking_inset) {
910 UnlockInsetInInset(bv, the_locking_inset);
911 the_locking_inset = 0;
913 if (bv->text->first + bv->painter().paperHeight() <
914 (top_baseline + tabular->GetHeightOfTabular()))
916 bv->scrollCB(bv->text->first + bv->painter().paperHeight());
917 UpdateLocal(bv, FULL, false);
918 actcell = tabular->GetCellBelow(first_visible_cell) + column;
920 actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
923 UpdateLocal(bv, CURSOR, false);
928 if (the_locking_inset) {
929 UnlockInsetInInset(bv, the_locking_inset);
930 the_locking_inset = 0;
932 if (top_baseline < 0) {
933 bv->scrollCB(bv->text->first - bv->painter().paperHeight());
934 UpdateLocal(bv, FULL, false);
935 if (top_baseline > 0)
938 actcell = tabular->GetCellBelow(first_visible_cell) + column;
943 UpdateLocal(bv, CURSOR, false);
954 case LFUN_LAYOUT_TABULAR:
956 bv->owner()->getDialogs()->showTabular(this);
959 case LFUN_TABULAR_FEATURE:
960 if (!TabularFeatures(bv, arg))
961 result = UNDISPATCHED;
964 if (!copySelection(bv))
966 bv->text->setUndo(bv->buffer(), Undo::DELETE,
967 bv->text->cursor.par()->previous(),
968 bv->text->cursor.par()->next());
970 UpdateLocal(bv, INIT, true);
975 bv->text->finishUndo();
978 case LFUN_PASTESELECTION:
980 string const clip(bv->getClipboard());
984 if (clip.find('\t') != string::npos) {
988 unsigned int len = clip.length();
989 string::size_type p = 0;
992 ((p = clip.find_first_of("\t\n", p)) != string::npos)) {
1000 maxCols = max(cols, maxCols);
1006 maxCols = max(cols, maxCols);
1007 delete paste_tabular;
1008 paste_tabular = new LyXTabular(this, rows, maxCols);
1009 string::size_type op = 0;
1011 int cells = paste_tabular->GetNumberOfCells();
1013 while((cell < cells) && (p < len) &&
1014 (p = clip.find_first_of("\t\n", p)) != string::npos) {
1019 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
1024 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
1025 while(cols++ < maxCols)
1033 // check for the last cell if there is no trailing '\n'
1034 if ((cell < cells) && (op < len))
1035 paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, len-op));
1037 // so that the clipboard is used and it goes on
1039 // and executes LFUN_PASTESELECTION in insettext!
1040 delete paste_tabular;
1045 if (hasPasteBuffer()) {
1046 bv->text->setUndo(bv->buffer(), Undo::INSERT,
1047 bv->text->cursor.par()->previous(),
1048 bv->text->cursor.par()->next());
1050 UpdateLocal(bv, INIT, true);
1053 // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
1055 // we try to activate the actual inset and put this event down to
1056 // the insets dispatch function.
1057 result = UNDISPATCHED;
1058 if (the_locking_inset)
1061 if (ActivateCellInset(bv)) {
1062 // reset need_update setted in above function!
1064 result = the_locking_inset->LocalDispatch(bv, action, arg);
1065 if ((result == UNDISPATCHED) || (result == FINISHED)) {
1066 UnlockInsetInInset(bv, the_locking_inset);
1068 the_locking_inset = 0;
1069 // we need to update if this was requested before
1070 UpdateLocal(bv, NONE, false);
1071 return UNDISPATCHED;
1074 // the_locking_inset->ToggleInsetCursor(bv);
1075 UpdateLocal(bv, CELL, false);
1076 // the_locking_inset->ToggleInsetCursor(bv);
1081 if (result!=FINISHED) {
1082 if (!the_locking_inset) {
1083 ShowInsetCursor(bv);
1086 bv->unlockInset(this);
1091 int InsetTabular::Latex(Buffer const * buf, ostream & os,
1092 bool fragile, bool fp) const
1094 return tabular->Latex(buf, os, fragile, fp);
1098 int InsetTabular::Ascii(Buffer const * buf, ostream & os, int) const
1100 // This should be changed to a real ascii export
1101 return tabular->Ascii(buf, os);
1105 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
1111 int InsetTabular::DocBook(Buffer const * buf, ostream & os) const
1113 return tabular->DocBook(buf,os);
1117 void InsetTabular::Validate(LaTeXFeatures & features) const
1119 tabular->Validate(features);
1123 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
1124 LyXFont const & font,
1131 bool changed = false;
1133 // if we have a locking_inset we should have to check only this cell for
1134 // change so I'll try this to have a boost, but who knows ;)
1135 if ((need_update != INIT) &&
1136 (the_locking_inset == tabular->GetCellInset(actcell))) {
1137 for(int i = 0; i < tabular->columns(); ++i) {
1138 maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
1140 maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
1143 changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
1144 changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
1145 changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
1151 for (int i = 0; i < tabular->rows(); ++i) {
1154 for (int j = 0; j < tabular->columns(); ++j) {
1155 if (tabular->IsPartOfMultiColumn(i,j))
1158 inset = tabular->GetCellInset(cell);
1160 inset->update(bv, font, false);
1161 maxAsc = max(maxAsc, inset->ascent(bv, font));
1162 maxDesc = max(maxDesc, inset->descent(bv, font));
1163 changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
1165 changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
1166 changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
1172 void InsetTabular::GetCursorPos(BufferView *,
1173 int & x, int & y) const
1175 x = cursor.x() - top_x;
1180 void InsetTabular::ToggleInsetCursor(BufferView * bv)
1182 if (the_locking_inset) {
1183 the_locking_inset->ToggleInsetCursor(bv);
1187 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
1189 int const asc = lyxfont::maxAscent(font);
1190 int const desc = lyxfont::maxDescent(font);
1192 if (isCursorVisible())
1193 bv->hideLockedInsetCursor();
1195 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1196 toggleCursorVisible();
1200 void InsetTabular::ShowInsetCursor(BufferView * bv, bool show)
1202 if (!isCursorVisible()) {
1203 LyXFont font; // = GetFont(par, cursor.pos);
1205 int const asc = lyxfont::maxAscent(font);
1206 int const desc = lyxfont::maxDescent(font);
1207 bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1209 bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
1210 setCursorVisible(true);
1215 void InsetTabular::HideInsetCursor(BufferView * bv)
1217 if (isCursorVisible()) {
1218 bv->hideLockedInsetCursor();
1219 setCursorVisible(false);
1221 // if (cursor_visible)
1222 // ToggleInsetCursor(bv);
1226 void InsetTabular::setPos(BufferView * bv, int x, int y) const
1230 actcell = actrow = actcol = 0;
1231 int ly = tabular->GetDescentOfRow(actrow);
1233 // first search the right row
1234 while((ly < y) && (actrow < tabular->rows())) {
1235 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1236 tabular->GetAscentOfRow(actrow + 1) +
1237 tabular->GetAdditionalHeight(actrow + 1));
1239 ly = cursor.y() + tabular->GetDescentOfRow(actrow);
1241 actcell = tabular->GetCellNumber(actrow, actcol);
1243 // now search the right column
1244 int lx = tabular->GetWidthOfColumn(actcell) -
1245 tabular->GetAdditionalWidth(actcell);
1247 #ifdef WITH_WARNINGS
1248 #warning Jürgen, can you rewrite this to _not_ use the sequencing operator. (Lgb)
1250 for (; !tabular->IsLastCellInRow(actcell) && (lx < x);
1251 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
1252 tabular->GetAdditionalWidth(actcell - 1));
1254 // Jürgen, you should check that this is correct. (Lgb)
1255 for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
1256 lx += tabular->GetWidthOfColumn(actcell + 1)
1257 + tabular->GetAdditionalWidth(actcell);
1261 cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
1266 int InsetTabular::getCellXPos(int cell) const
1270 for (; !tabular->IsFirstCellInRow(c); --c)
1272 int lx = tabular->GetWidthOfColumn(cell);
1273 for (; c < cell; ++c) {
1274 lx += tabular->GetWidthOfColumn(c);
1276 return (lx - tabular->GetWidthOfColumn(cell) + top_x);
1280 void InsetTabular::resetPos(BufferView * bv) const
1284 actcol = tabular->column_of_cell(actcell);
1289 for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
1290 if (tabular->IsLastCellInRow(cell)) {
1291 cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
1292 tabular->GetAscentOfRow(actrow + 1) +
1293 tabular->GetAdditionalHeight(actrow + 1));
1297 static int const offset = ADD_TO_TABULAR_WIDTH + 2;
1298 int new_x = getCellXPos(actcell);
1299 int old_x = cursor.x();
1302 // cursor.x(getCellXPos(actcell) + offset);
1303 if ((actcol < tabular->columns()-1) && scroll(false) &&
1304 (tabular->GetWidthOfTabular() < bv->workWidth()-20))
1307 UpdateLocal(bv, FULL, false);
1308 } else if (the_locking_inset &&
1309 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
1311 int xx = cursor.x() - offset + bv->text->getRealCursorX(bv);
1312 if (xx > (bv->workWidth()-20)) {
1313 scroll(bv, -(xx - bv->workWidth() + 60));
1314 UpdateLocal(bv, FULL, false);
1315 } else if (xx < 20) {
1321 UpdateLocal(bv, FULL, false);
1323 } else if ((cursor.x() - offset) > 20 &&
1324 (cursor.x() - offset + tabular->GetWidthOfColumn(actcell))
1325 > (bv->workWidth() - 20)) {
1326 scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
1327 UpdateLocal(bv, FULL, false);
1328 } else if ((cursor.x() - offset) < 20) {
1329 scroll(bv, 20 - cursor.x() + offset);
1330 UpdateLocal(bv, FULL, false);
1331 } else if (scroll(false) && top_x > 20 &&
1332 (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
1333 scroll(bv, old_x - cursor.x());
1334 UpdateLocal(bv, FULL, false);
1336 if ((!the_locking_inset ||
1337 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
1338 actcell != oldcell) {
1339 InsetTabular * inset = const_cast<InsetTabular *>(this);
1340 bv->owner()->getDialogs()->updateTabular(inset);
1346 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
1348 if (lock && !old_locking_inset) {
1349 if (ActivateCellInset(bv))
1352 bool moved = isRightToLeft(bv)
1353 ? movePrevCell(bv) : moveNextCell(bv);
1356 if (lock && ActivateCellInset(bv))
1360 return DISPATCHED_NOUPDATE;
1364 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
1366 bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
1369 if (lock) { // behind the inset
1370 if (ActivateCellInset(bv, 0, 0, 0, true))
1374 return DISPATCHED_NOUPDATE;
1378 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
1380 int const ocell = actcell;
1381 actcell = tabular->GetCellAbove(actcell);
1382 if (actcell == ocell) // we moved out of the inset
1388 if (old_locking_inset) {
1389 old_locking_inset->GetCursorPos(bv, x, y);
1390 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1392 if (ActivateCellInset(bv, x, 0))
1395 return DISPATCHED_NOUPDATE;
1399 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
1401 int const ocell = actcell;
1402 actcell = tabular->GetCellBelow(actcell);
1403 if (actcell == ocell) // we moved out of the inset
1409 if (old_locking_inset) {
1410 old_locking_inset->GetCursorPos(bv, x, y);
1411 x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1413 if (ActivateCellInset(bv, x, 0))
1416 return DISPATCHED_NOUPDATE;
1420 bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
1422 if (isRightToLeft(bv)) {
1423 if (tabular->IsFirstCellInRow(actcell)) {
1424 int row = tabular->row_of_cell(actcell);
1425 if (row == tabular->rows() - 1)
1427 actcell = tabular->GetLastCellInRow(row);
1428 actcell = tabular->GetCellBelow(actcell);
1435 if (tabular->IsLastCell(actcell))
1440 bool rtl = tabular->GetCellInset(actcell)->par->
1441 isRightToLeftPar(bv->buffer()->params);
1442 ActivateCellInset(bv, 0, 0, 0, !rtl);
1449 bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
1451 if (isRightToLeft(bv)) {
1452 if (tabular->IsLastCellInRow(actcell)) {
1453 int row = tabular->row_of_cell(actcell);
1456 actcell = tabular->GetFirstCellInRow(row);
1457 actcell = tabular->GetCellAbove(actcell);
1459 if (tabular->IsLastCell(actcell))
1464 if (!actcell) // first cell
1469 bool rtl = tabular->GetCellInset(actcell)->par->
1470 isRightToLeftPar(bv->buffer()->params);
1471 ActivateCellInset(bv, 0, 0, 0, !rtl);
1478 bool InsetTabular::Delete()
1484 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall,
1489 sel_cell_end = tabular->GetNumberOfCells() - 1;
1491 if (hasSelection()) {
1493 bv->text->setUndo(bv->buffer(), Undo::EDIT,
1494 bv->text->cursor.par()->previous(),
1495 bv->text->cursor.par()->next());
1496 frozen = bv->text->undo_frozen;
1498 bv->text->freezeUndo();
1499 // apply the fontchange on the whole selection
1504 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1505 for(int i=sel_row_start; i <= sel_row_end; ++i) {
1506 for(int j=sel_col_start; j <= sel_col_end; ++j) {
1507 tabular->GetCellInset(i, j)->SetFont(bv, font, tall, true);
1511 bv->text->unFreezeUndo();
1512 UpdateLocal(bv, INIT, true);
1514 if (the_locking_inset)
1515 the_locking_inset->SetFont(bv, font, tall);
1519 bool InsetTabular::TabularFeatures(BufferView * bv, string const & what)
1521 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1524 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
1525 string const tmp = tabularFeatures[i].feature;
1527 if (tmp == what.substr(0, tmp.length())) {
1528 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1529 //tabularFeatures[i].feature.length())) {
1530 action = tabularFeatures[i].action;
1534 if (action == LyXTabular::LAST_ACTION)
1538 frontStrip(what.substr(tabularFeatures[i].feature.length()));
1539 TabularFeatures(bv, action, val);
1544 void InsetTabular::TabularFeatures(BufferView * bv,
1545 LyXTabular::Feature feature,
1546 string const & value)
1554 bool setLines = false;
1555 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1556 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1561 case LyXTabular::M_ALIGN_LEFT:
1562 case LyXTabular::ALIGN_LEFT:
1563 setAlign=LYX_ALIGN_LEFT;
1565 case LyXTabular::M_ALIGN_RIGHT:
1566 case LyXTabular::ALIGN_RIGHT:
1567 setAlign=LYX_ALIGN_RIGHT;
1569 case LyXTabular::M_ALIGN_CENTER:
1570 case LyXTabular::ALIGN_CENTER:
1571 setAlign=LYX_ALIGN_CENTER;
1573 case LyXTabular::M_VALIGN_TOP:
1574 case LyXTabular::VALIGN_TOP:
1575 setVAlign=LyXTabular::LYX_VALIGN_TOP;
1577 case LyXTabular::M_VALIGN_BOTTOM:
1578 case LyXTabular::VALIGN_BOTTOM:
1579 setVAlign=LyXTabular::LYX_VALIGN_BOTTOM;
1581 case LyXTabular::M_VALIGN_CENTER:
1582 case LyXTabular::VALIGN_CENTER:
1583 setVAlign=LyXTabular::LYX_VALIGN_CENTER;
1588 if (hasSelection()) {
1589 getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1591 sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1592 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1594 bv->text->setUndo(bv->buffer(), Undo::FINISH,
1595 bv->text->cursor.par()->previous(),
1596 bv->text->cursor.par()->next());
1598 int row = tabular->row_of_cell(actcell);
1599 int column = tabular->column_of_cell(actcell);
1603 case LyXTabular::SET_PWIDTH:
1605 bool const update = (tabular->GetColumnPWidth(actcell) != value);
1606 tabular->SetColumnPWidth(actcell,value);
1608 for (int i = 0; i < tabular->rows(); ++i) {
1609 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1612 UpdateLocal(bv, INIT, true);
1616 case LyXTabular::SET_MPWIDTH:
1618 bool const update = (tabular->GetPWidth(actcell) != value);
1619 tabular->SetMColumnPWidth(actcell,value);
1621 for (int i = 0; i < tabular->rows(); ++i) {
1622 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1625 UpdateLocal(bv, INIT, true);
1629 case LyXTabular::SET_SPECIAL_COLUMN:
1630 case LyXTabular::SET_SPECIAL_MULTI:
1631 tabular->SetAlignSpecial(actcell,value,feature);
1633 case LyXTabular::APPEND_ROW:
1634 // append the row into the tabular
1635 UnlockInsetInInset(bv, the_locking_inset);
1636 tabular->AppendRow(actcell);
1637 UpdateLocal(bv, INIT, true);
1639 case LyXTabular::APPEND_COLUMN:
1640 // append the column into the tabular
1641 UnlockInsetInInset(bv, the_locking_inset);
1642 tabular->AppendColumn(actcell);
1643 actcell = tabular->GetCellNumber(row, column);
1644 UpdateLocal(bv, INIT, true);
1646 case LyXTabular::DELETE_ROW:
1647 UnlockInsetInInset(bv, the_locking_inset);
1648 tabular->DeleteRow(tabular->row_of_cell(actcell));
1649 if ((row+1) > tabular->rows())
1651 actcell = tabular->GetCellNumber(row, column);
1653 UpdateLocal(bv, INIT, true);
1655 case LyXTabular::DELETE_COLUMN:
1656 UnlockInsetInInset(bv, the_locking_inset);
1657 tabular->DeleteColumn(tabular->column_of_cell(actcell));
1658 if ((column+1) > tabular->columns())
1660 actcell = tabular->GetCellNumber(row, column);
1662 UpdateLocal(bv, INIT, true);
1664 case LyXTabular::M_TOGGLE_LINE_TOP:
1666 case LyXTabular::TOGGLE_LINE_TOP:
1668 bool lineSet = !tabular->TopLine(actcell, flag);
1669 for (int i = sel_row_start; i <= sel_row_end; ++i)
1670 for (int j = sel_col_start; j <= sel_col_end; ++j)
1671 tabular->SetTopLine(
1672 tabular->GetCellNumber(i, j),
1674 UpdateLocal(bv, INIT, true);
1678 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1680 case LyXTabular::TOGGLE_LINE_BOTTOM:
1682 bool lineSet = !tabular->BottomLine(actcell, flag);
1683 for (int i = sel_row_start; i <= sel_row_end; ++i)
1684 for (int j = sel_col_start; j <= sel_col_end; ++j)
1685 tabular->SetBottomLine(
1686 tabular->GetCellNumber(i, j),
1689 UpdateLocal(bv, INIT, true);
1693 case LyXTabular::M_TOGGLE_LINE_LEFT:
1695 case LyXTabular::TOGGLE_LINE_LEFT:
1697 bool lineSet = !tabular->LeftLine(actcell, flag);
1698 for (int i = sel_row_start; i <= sel_row_end; ++i)
1699 for (int j = sel_col_start; j <= sel_col_end; ++j)
1700 tabular->SetLeftLine(
1701 tabular->GetCellNumber(i,j),
1704 UpdateLocal(bv, INIT, true);
1708 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1710 case LyXTabular::TOGGLE_LINE_RIGHT:
1712 bool lineSet = !tabular->RightLine(actcell, flag);
1713 for (int i = sel_row_start; i <= sel_row_end; ++i)
1714 for (int j = sel_col_start; j <= sel_col_end; ++j)
1715 tabular->SetRightLine(
1716 tabular->GetCellNumber(i,j),
1719 UpdateLocal(bv, INIT, true);
1723 case LyXTabular::M_ALIGN_LEFT:
1724 case LyXTabular::M_ALIGN_RIGHT:
1725 case LyXTabular::M_ALIGN_CENTER:
1727 case LyXTabular::ALIGN_LEFT:
1728 case LyXTabular::ALIGN_RIGHT:
1729 case LyXTabular::ALIGN_CENTER:
1730 for (int i = sel_row_start; i <= sel_row_end; ++i)
1731 for (int j = sel_col_start; j <= sel_col_end; ++j)
1732 tabular->SetAlignment(
1733 tabular->GetCellNumber(i, j),
1736 UpdateLocal(bv, INIT, true);
1738 case LyXTabular::M_VALIGN_TOP:
1739 case LyXTabular::M_VALIGN_BOTTOM:
1740 case LyXTabular::M_VALIGN_CENTER:
1742 case LyXTabular::VALIGN_TOP:
1743 case LyXTabular::VALIGN_BOTTOM:
1744 case LyXTabular::VALIGN_CENTER:
1745 for (int i = sel_row_start; i <= sel_row_end; ++i)
1746 for (int j = sel_col_start; j <= sel_col_end; ++j)
1747 tabular->SetVAlignment(
1748 tabular->GetCellNumber(i, j),
1750 UpdateLocal(bv, INIT, true);
1752 case LyXTabular::MULTICOLUMN:
1754 if (sel_row_start != sel_row_end) {
1755 WriteAlert(_("Impossible Operation!"),
1756 _("Multicolumns can only be horizontally."),
1760 // just multicol for one Single Cell
1761 if (!hasSelection()) {
1762 // check wether we are completly in a multicol
1763 if (tabular->IsMultiColumn(actcell)) {
1764 tabular->UnsetMultiColumn(actcell);
1765 UpdateLocal(bv, INIT, true);
1767 tabular->SetMultiColumn(actcell, 1);
1768 UpdateLocal(bv, CELL, true);
1772 // we have a selection so this means we just add all this
1773 // cells to form a multicolumn cell
1777 if (sel_cell_start > sel_cell_end) {
1778 s_start = sel_cell_end;
1779 s_end = sel_cell_start;
1781 s_start = sel_cell_start;
1782 s_end = sel_cell_end;
1784 tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1786 sel_cell_end = sel_cell_start;
1787 UpdateLocal(bv, INIT, true);
1790 case LyXTabular::SET_ALL_LINES:
1792 case LyXTabular::UNSET_ALL_LINES:
1793 for (int i = sel_row_start; i <= sel_row_end; ++i)
1794 for (int j = sel_col_start; j <= sel_col_end; ++j)
1795 tabular->SetAllLines(
1796 tabular->GetCellNumber(i,j), setLines);
1797 UpdateLocal(bv, INIT, true);
1799 case LyXTabular::SET_LONGTABULAR:
1800 tabular->SetLongTabular(true);
1801 UpdateLocal(bv, INIT, true); // because this toggles displayed
1803 case LyXTabular::UNSET_LONGTABULAR:
1804 tabular->SetLongTabular(false);
1805 UpdateLocal(bv, INIT, true); // because this toggles displayed
1807 case LyXTabular::SET_ROTATE_TABULAR:
1808 tabular->SetRotateTabular(true);
1810 case LyXTabular::UNSET_ROTATE_TABULAR:
1811 tabular->SetRotateTabular(false);
1813 case LyXTabular::SET_ROTATE_CELL:
1814 for (int i = sel_row_start; i <= sel_row_end; ++i)
1815 for (int j = sel_col_start; j<=sel_col_end; ++j)
1816 tabular->SetRotateCell(
1817 tabular->GetCellNumber(i, j),
1820 case LyXTabular::UNSET_ROTATE_CELL:
1821 for (int i = sel_row_start; i <= sel_row_end; ++i)
1822 for (int j = sel_col_start; j <= sel_col_end; ++j)
1823 tabular->SetRotateCell(
1824 tabular->GetCellNumber(i, j), false);
1826 case LyXTabular::SET_USEBOX:
1828 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1829 if (val == tabular->GetUsebox(actcell))
1830 val = LyXTabular::BOX_NONE;
1831 for (int i = sel_row_start; i <= sel_row_end; ++i)
1832 for (int j = sel_col_start; j <= sel_col_end; ++j)
1834 tabular->GetCellNumber(i, j), val);
1837 case LyXTabular::SET_LTFIRSTHEAD:
1838 tabular->SetLTHead(actcell, true);
1840 case LyXTabular::SET_LTHEAD:
1841 tabular->SetLTHead(actcell, false);
1843 case LyXTabular::SET_LTFOOT:
1844 tabular->SetLTFoot(actcell, false);
1846 case LyXTabular::SET_LTLASTFOOT:
1847 tabular->SetLTFoot(actcell, true);
1849 case LyXTabular::SET_LTNEWPAGE:
1851 bool what = !tabular->GetLTNewPage(actcell);
1852 tabular->SetLTNewPage(actcell, what);
1855 // dummy stuff just to avoid warnings
1856 case LyXTabular::LAST_ACTION:
1862 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1865 UpdatableInset * inset =
1866 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1867 LyXFont font(LyXFont::ALL_SANE);
1869 x = inset->x() + inset->width(bv, font);
1870 y = inset->descent(bv, font);
1872 //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1873 //inset_y = cursor.y();
1874 inset->Edit(bv, x, y, button);
1875 if (!the_locking_inset)
1877 UpdateLocal(bv, CELL, false);
1878 return (the_locking_inset != 0);
1882 bool InsetTabular::ActivateCellInsetAbs(BufferView * bv, int x, int y,
1885 inset_x = cursor.x()
1886 - top_x + tabular->GetBeginningOfTextInCell(actcell);
1887 inset_y = cursor.y();
1888 return ActivateCellInset(bv, x - inset_x, y - inset_y, button);
1892 bool InsetTabular::InsetHit(BufferView *, int x, int) const
1895 > (cursor.x() + tabular->GetBeginningOfTextInCell(actcell));
1899 // This returns paperWidth() if the cell-width is unlimited or the width
1900 // in pixels if we have a pwidth for this cell.
1901 int InsetTabular::GetMaxWidthOfCell(BufferView * bv, int cell) const
1903 string const s = tabular->GetPWidth(cell);
1907 return VSpace(s).inPixels(bv);
1911 int InsetTabular::getMaxWidth(BufferView * bv,
1912 UpdatableInset const * inset) const
1914 int cell = tabular->cur_cell;
1915 if (tabular->GetCellInset(cell) != inset) {
1917 if (tabular->GetCellInset(cell) != inset) {
1918 lyxerr << "Actcell not equal to actual cell!" << std::endl;
1924 int const n = tabular->GetNumberOfCells();
1928 for (; cell < n; ++cell) {
1929 if (tabular->GetCellInset(cell) == inset)
1938 int w = GetMaxWidthOfCell(bv, cell);
1940 // because the inset then subtracts it's top_x and owner->x()
1941 w += (inset->x() - top_x);
1948 void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
1950 resizeLyXText(bv, recursive);
1954 void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
1957 for(int i = 0; i < tabular->rows(); ++i) {
1958 for(int j = 0; j < tabular->columns(); ++j) {
1959 tabular->GetCellInset(i, j)->resizeLyXText(bv, true);
1967 LyXText * InsetTabular::getLyXText(BufferView const * bv,
1968 bool const recursive) const
1970 if (the_locking_inset)
1971 return the_locking_inset->getLyXText(bv, recursive);
1972 return Inset::getLyXText(bv, recursive);
1976 bool InsetTabular::ShowInsetDialog(BufferView * bv) const
1978 if (!the_locking_inset || !the_locking_inset->ShowInsetDialog(bv))
1979 bv->owner()->getDialogs()
1980 ->showTabular(const_cast<InsetTabular *>(this));
1985 void InsetTabular::OpenLayoutDialog(BufferView * bv) const
1987 if (the_locking_inset) {
1988 InsetTabular * i = static_cast<InsetTabular *>
1989 (the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE));
1991 i->OpenLayoutDialog(bv);
1995 bv->owner()->getDialogs()->showTabular(
1996 const_cast<InsetTabular *>(this));
2000 // functions returns:
2004 // 3 ... toggled off
2006 func_status::value_type InsetTabular::getStatus(string const & what) const
2008 int action = LyXTabular::LAST_ACTION;
2009 func_status::value_type status = func_status::OK;
2012 for (; tabularFeatures[i].action != LyXTabular::LAST_ACTION; ++i) {
2013 string const tmp = tabularFeatures[i].feature;
2014 if (tmp == what.substr(0, tmp.length())) {
2015 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
2016 // tabularFeatures[i].feature.length())) {
2017 action = tabularFeatures[i].action;
2021 if (action == LyXTabular::LAST_ACTION)
2022 return func_status::Unknown;
2024 string const argument = frontStrip(what.substr(tabularFeatures[i].feature.length()));
2031 if (hasSelection()) {
2032 getSelection(sel_row_start, sel_row_end, dummy, dummy);
2034 sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
2038 case LyXTabular::SET_PWIDTH:
2039 case LyXTabular::SET_MPWIDTH:
2040 case LyXTabular::SET_SPECIAL_COLUMN:
2041 case LyXTabular::SET_SPECIAL_MULTI:
2042 status |= func_status::Disabled;
2045 case LyXTabular::APPEND_ROW:
2046 case LyXTabular::APPEND_COLUMN:
2047 case LyXTabular::DELETE_ROW:
2048 case LyXTabular::DELETE_COLUMN:
2049 case LyXTabular::SET_ALL_LINES:
2050 case LyXTabular::UNSET_ALL_LINES:
2051 status |= func_status::OK;
2054 case LyXTabular::MULTICOLUMN:
2055 if (tabular->IsMultiColumn(actcell))
2056 status |= func_status::ToggleOn;
2058 status |= func_status::ToggleOff;
2060 case LyXTabular::M_TOGGLE_LINE_TOP:
2062 case LyXTabular::TOGGLE_LINE_TOP:
2063 if (tabular->TopLine(actcell, flag))
2064 status |= func_status::ToggleOn;
2066 status |= func_status::ToggleOff;
2068 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
2070 case LyXTabular::TOGGLE_LINE_BOTTOM:
2071 if (tabular->BottomLine(actcell, flag))
2072 status |= func_status::ToggleOn;
2074 status |= func_status::ToggleOff;
2076 case LyXTabular::M_TOGGLE_LINE_LEFT:
2078 case LyXTabular::TOGGLE_LINE_LEFT:
2079 if (tabular->LeftLine(actcell, flag))
2080 status |= func_status::ToggleOn;
2082 status |= func_status::ToggleOff;
2084 case LyXTabular::M_TOGGLE_LINE_RIGHT:
2086 case LyXTabular::TOGGLE_LINE_RIGHT:
2087 if (tabular->RightLine(actcell, flag))
2088 status |= func_status::ToggleOn;
2090 status |= func_status::ToggleOff;
2092 case LyXTabular::M_ALIGN_LEFT:
2094 case LyXTabular::ALIGN_LEFT:
2095 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_LEFT)
2096 status |= func_status::ToggleOn;
2098 status |= func_status::ToggleOff;
2100 case LyXTabular::M_ALIGN_RIGHT:
2102 case LyXTabular::ALIGN_RIGHT:
2103 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_RIGHT)
2104 status |= func_status::ToggleOn;
2106 status |= func_status::ToggleOff;
2108 case LyXTabular::M_ALIGN_CENTER:
2110 case LyXTabular::ALIGN_CENTER:
2111 if (tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER)
2112 status |= func_status::ToggleOn;
2114 status |= func_status::ToggleOff;
2116 case LyXTabular::M_VALIGN_TOP:
2118 case LyXTabular::VALIGN_TOP:
2119 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP)
2120 status |= func_status::ToggleOn;
2122 status |= func_status::ToggleOff;
2124 case LyXTabular::M_VALIGN_BOTTOM:
2126 case LyXTabular::VALIGN_BOTTOM:
2127 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM)
2128 status |= func_status::ToggleOn;
2130 status |= func_status::ToggleOff;
2132 case LyXTabular::M_VALIGN_CENTER:
2134 case LyXTabular::VALIGN_CENTER:
2135 if (tabular->GetVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_CENTER)
2136 status |= func_status::ToggleOn;
2138 status |= func_status::ToggleOff;
2140 case LyXTabular::SET_LONGTABULAR:
2141 if (tabular->IsLongTabular())
2142 status |= func_status::ToggleOn;
2144 status |= func_status::ToggleOff;
2146 case LyXTabular::UNSET_LONGTABULAR:
2147 if (!tabular->IsLongTabular())
2148 status |= func_status::ToggleOn;
2150 status |= func_status::ToggleOff;
2152 case LyXTabular::SET_ROTATE_TABULAR:
2153 if (tabular->GetRotateTabular())
2154 status |= func_status::ToggleOn;
2156 status |= func_status::ToggleOff;
2158 case LyXTabular::UNSET_ROTATE_TABULAR:
2159 if (!tabular->GetRotateTabular())
2160 status |= func_status::ToggleOn;
2162 status |= func_status::ToggleOff;
2164 case LyXTabular::SET_ROTATE_CELL:
2165 if (tabular->GetRotateCell(actcell))
2166 status |= func_status::ToggleOn;
2168 status |= func_status::ToggleOff;
2170 case LyXTabular::UNSET_ROTATE_CELL:
2171 if (!tabular->GetRotateCell(actcell))
2172 status |= func_status::ToggleOn;
2174 status |= func_status::ToggleOff;
2176 case LyXTabular::SET_USEBOX:
2177 if (strToInt(argument) == tabular->GetUsebox(actcell))
2178 status |= func_status::ToggleOn;
2180 status |= func_status::ToggleOff;
2182 case LyXTabular::SET_LTFIRSTHEAD:
2183 if (tabular->GetRowOfLTHead(actcell, dummy))
2184 status |= func_status::ToggleOn;
2186 status |= func_status::ToggleOff;
2188 case LyXTabular::SET_LTHEAD:
2189 if (tabular->GetRowOfLTHead(actcell, dummy))
2190 status |= func_status::ToggleOn;
2192 status |= func_status::ToggleOff;
2194 case LyXTabular::SET_LTFOOT:
2195 if (tabular->GetRowOfLTFoot(actcell, dummy))
2196 status |= func_status::ToggleOn;
2198 status |= func_status::ToggleOff;
2200 case LyXTabular::SET_LTLASTFOOT:
2201 if (tabular->GetRowOfLTFoot(actcell, dummy))
2202 status |= func_status::ToggleOn;
2204 status |= func_status::ToggleOff;
2206 case LyXTabular::SET_LTNEWPAGE:
2207 if (tabular->GetLTNewPage(actcell))
2208 status |= func_status::ToggleOn;
2210 status |= func_status::ToggleOff;
2213 status = func_status::Disabled;
2220 std::vector<string> const InsetTabular::getLabelList() const
2222 return tabular->getLabelList();
2226 bool InsetTabular::copySelection(BufferView * bv)
2228 if (!hasSelection())
2231 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2232 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2233 if (sel_col_start > sel_col_end) {
2234 sel_col_start = sel_col_end;
2235 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2237 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2239 int const columns = sel_col_end - sel_col_start + 1;
2241 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2242 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2243 if (sel_row_start > sel_row_end) {
2244 swap(sel_row_start, sel_row_end);
2246 int const rows = sel_row_end - sel_row_start + 1;
2248 delete paste_tabular;
2249 paste_tabular = new LyXTabular(this, *tabular); // rows, columns);
2250 for (int i = 0; i < sel_row_start; ++i)
2251 paste_tabular->DeleteRow(0);
2252 while(paste_tabular->rows() > rows)
2253 paste_tabular->DeleteRow(rows);
2254 paste_tabular->SetTopLine(0, true, true);
2255 paste_tabular->SetBottomLine(paste_tabular->GetFirstCellInRow(rows-1),
2257 for (int i = 0; i < sel_col_start; ++i)
2258 paste_tabular->DeleteColumn(0);
2259 while (paste_tabular->columns() > columns)
2260 paste_tabular->DeleteColumn(columns);
2261 paste_tabular->SetLeftLine(0, true, true);
2262 paste_tabular->SetRightLine(paste_tabular->GetLastCellInRow(0),
2266 paste_tabular->Ascii(bv->buffer(), sstr);
2267 bv->stuffClipboard(sstr.str().c_str());
2272 bool InsetTabular::pasteSelection(BufferView * bv)
2277 for (int r1 = 0, r2 = actrow;
2278 (r1 < paste_tabular->rows()) && (r2 < tabular->rows());
2280 for(int c1 = 0, c2 = actcol;
2281 (c1 < paste_tabular->columns()) && (c2 < tabular->columns());
2283 if (paste_tabular->IsPartOfMultiColumn(r1,c1) &&
2284 tabular->IsPartOfMultiColumn(r2,c2))
2286 if (paste_tabular->IsPartOfMultiColumn(r1,c1)) {
2290 if (tabular->IsPartOfMultiColumn(r2,c2)) {
2294 int const n1 = paste_tabular->GetCellNumber(r1, c1);
2295 int const n2 = tabular->GetCellNumber(r2, c2);
2296 *(tabular->GetCellInset(n2)) = *(paste_tabular->GetCellInset(n1));
2297 tabular->GetCellInset(n2)->setOwner(this);
2298 tabular->GetCellInset(n2)->deleteLyXText(bv);
2305 bool InsetTabular::cutSelection()
2307 if (!hasSelection())
2310 //int sel_col_start;
2312 //int sel_row_start;
2315 int sel_col_start = tabular->column_of_cell(sel_cell_start);
2316 int sel_col_end = tabular->column_of_cell(sel_cell_end);
2317 if (sel_col_start > sel_col_end) {
2318 sel_col_start = sel_col_end;
2319 sel_col_end = tabular->right_column_of_cell(sel_cell_start);
2321 sel_col_end = tabular->right_column_of_cell(sel_cell_end);
2323 int sel_row_start = tabular->row_of_cell(sel_cell_start);
2324 int sel_row_end = tabular->row_of_cell(sel_cell_end);
2325 if (sel_row_start > sel_row_end) {
2326 //int tmp = sel_row_start;
2327 //sel_row_start = sel_row_end;
2328 //sel_row_end = tmp;
2329 swap(sel_row_start, sel_row_end);
2331 if (sel_cell_start > sel_cell_end) {
2332 //int tmp = sel_cell_start;
2333 //sel_cell_start = sel_cell_end;
2334 //sel_cell_end = tmp;
2335 swap(sel_cell_start, sel_cell_end);
2337 for (int i = sel_row_start; i <= sel_row_end; ++i) {
2338 for (int j = sel_col_start; j <= sel_col_end; ++j) {
2339 tabular->GetCellInset(tabular->GetCellNumber(i, j))->clear();
2346 bool InsetTabular::isRightToLeft(BufferView *bv )
2348 return bv->getParentLanguage(this)->RightToLeft();
2352 bool InsetTabular::nodraw() const
2354 if (!UpdatableInset::nodraw() && the_locking_inset)
2355 return the_locking_inset->nodraw();
2356 return UpdatableInset::nodraw();
2360 int InsetTabular::scroll(bool recursive) const
2362 int sx = UpdatableInset::scroll(false);
2364 if (recursive && the_locking_inset)
2365 sx += the_locking_inset->scroll(recursive);
2371 bool InsetTabular::doClearArea() const
2373 return !locked || (need_update & (FULL|INIT));
2377 void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol) const
2379 srow = tabular->row_of_cell(sel_cell_start);
2380 erow = tabular->row_of_cell(sel_cell_end);
2384 scol = tabular->column_of_cell(sel_cell_start);
2385 ecol = tabular->column_of_cell(sel_cell_end);
2389 ecol = tabular->right_column_of_cell(sel_cell_end);