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"
26 #include "LaTeXFeatures.h"
30 #include "lyx_gui_misc.h"
33 #include "insets/insettext.h"
35 extern void MenuLayoutTabular(bool, InsetTabular *);
36 extern bool UpdateLayoutTabular(bool, InsetTabular *);
37 extern void TabularOptClose();
39 const int ADD_TO_HEIGHT = 2;
40 const int ADD_TO_TABULAR_WIDTH = 2;
48 InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
54 buffer = buf; // set this first!!!
55 tabular = new LyXTabular(this, rows,columns);
56 // for now make it always display as display() inset
58 the_locking_inset = 0;
59 locked = no_selection = cursor_visible = false;
62 actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
67 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
69 buffer = buf; // set this first
70 tabular = new LyXTabular(this, *(tab.tabular));
71 the_locking_inset = 0;
72 locked = no_selection = cursor_visible = false;
75 actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
80 InsetTabular::~InsetTabular()
86 Inset * InsetTabular::Clone() const
88 InsetTabular * t = new InsetTabular(*this, buffer);
90 t->tabular = tabular->Clone(t);
95 void InsetTabular::Write(ostream & os) const
97 os << " Tabular" << endl;
102 void InsetTabular::Read(LyXLex & lex)
104 bool old_format = (lex.GetString() == "\\LyXTable");
109 tabular = new LyXTabular(this, lex);
117 token = lex.GetString();
118 while (lex.IsOK() && (token != "\\end_inset")) {
120 token = lex.GetString();
122 if (token != "\\end_inset") {
123 lex.printError("Missing \\end_inset at this point. "
129 int InsetTabular::ascent(Painter & pain, LyXFont const & font) const
132 calculate_width_of_cells(pain, font);
135 return tabular->GetAscentOfRow(0);
139 int InsetTabular::descent(Painter & pain, LyXFont const & font) const
142 calculate_width_of_cells(pain, font);
145 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0);
149 int InsetTabular::width(Painter & pain, LyXFont const & font) const
152 calculate_width_of_cells(pain, font);
155 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
159 void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline,
167 UpdatableInset::draw(pain,font,baseline,x);
168 if (init_inset || (top_x != int(x)) || (top_baseline != baseline)) {
172 top_baseline = baseline;
174 recomputeTextInsets(pain, font);
175 calculate_width_of_cells(pain, font);
179 x += ADD_TO_TABULAR_WIDTH;
180 for(i=0;i<tabular->rows();++i) {
182 for(j=0;j<tabular->columns();++j) {
183 if (tabular->IsPartOfMultiColumn(i,j))
185 cx = nx + tabular->GetBeginningOfTextInCell(cell);
186 tabular->GetCellInset(cell)->draw(pain, font, baseline, cx);
187 DrawCellLines(pain, nx, baseline, i, cell);
188 nx += tabular->GetWidthOfColumn(cell);
191 baseline += tabular->GetDescentOfRow(i) + tabular->GetAscentOfRow(i+1)
192 + tabular->GetAdditionalHeight(cell+1);
194 x += width(pain, font);
198 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
199 int row, int cell) const
201 int x2 = x + tabular->GetWidthOfColumn(cell);
204 if (!tabular->TopAlreadyDrawed(cell)) {
205 on_off = !tabular->TopLine(cell);
206 pain.line(x, baseline - tabular->GetAscentOfRow(row),
207 x2, baseline - tabular->GetAscentOfRow(row),
208 on_off ? LColor::tabularonoffline:LColor::tabularline,
209 on_off ? Painter::line_onoffdash:Painter::line_solid);
211 on_off = !tabular->BottomLine(cell);
212 pain.line(x,baseline + tabular->GetDescentOfRow(row),
213 x2, baseline + tabular->GetDescentOfRow(row),
214 on_off ? LColor::tabularonoffline:LColor::tabularline,
215 on_off ? Painter::line_onoffdash:Painter::line_solid);
216 if (!tabular->LeftAlreadyDrawed(cell)) {
217 on_off = !tabular->LeftLine(cell);
218 pain.line(x, baseline - tabular->GetAscentOfRow(row),
219 x, baseline + tabular->GetDescentOfRow(row),
220 on_off ? LColor::tabularonoffline:LColor::tabularline,
221 on_off ? Painter::line_onoffdash:Painter::line_solid);
223 on_off = !tabular->RightLine(cell);
224 pain.line(x2 - tabular->GetAdditionalWidth(cell),
225 baseline - tabular->GetAscentOfRow(row),
226 x2 - tabular->GetAdditionalWidth(cell),
227 baseline + tabular->GetDescentOfRow(row),
228 on_off ? LColor::tabularonoffline:LColor::tabularline,
229 on_off ? Painter::line_onoffdash:Painter::line_solid);
233 char const * InsetTabular::EditMessage() const
235 return _("Opened Tabular Inset");
239 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
241 UpdatableInset::Edit(bv, x, y, button);
243 if (!bv->lockInset(this)) {
244 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
248 the_locking_inset = 0;
249 sel_pos_start = sel_pos_end = inset_pos = inset_x = inset_y = 0;
250 setPos(bv->painter(), x, y);
251 sel_pos_start = sel_pos_end = cursor.pos;
252 bv->text->FinishUndo();
253 if (InsetHit(bv, x, y)) {
254 ActivateCellInset(bv, x, y, button);
256 UpdateLocal(bv, true);
257 // bv->getOwner()->getPopups().updateFormTabular();
261 void InsetTabular::InsetUnlock(BufferView * bv)
264 if (the_locking_inset) {
265 the_locking_inset->InsetUnlock(bv);
266 the_locking_inset = 0;
269 if (hasCharSelection()) {
270 sel_pos_start = sel_pos_end = cursor.pos;
271 UpdateLocal(bv, false);
273 sel_pos_start = sel_pos_end = cursor.pos;
274 no_selection = false;
279 void InsetTabular::UpdateLocal(BufferView * bv, bool flag)
282 calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE));
283 bv->updateInset(this, flag);
285 resetPos(bv->painter());
288 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
290 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
294 if (inset == tabular->GetCellInset(actcell)) {
295 lyxerr[Debug::INSETS] << "OK" << endl;
296 the_locking_inset = tabular->GetCellInset(actcell);
297 resetPos(bv->painter());
298 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
300 inset_pos = cursor.pos;
302 } else if (the_locking_inset && (the_locking_inset == inset)) {
303 if (cursor.pos == inset_pos) {
304 lyxerr[Debug::INSETS] << "OK" << endl;
305 resetPos(bv->painter());
306 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
309 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
311 } else if (the_locking_inset) {
312 lyxerr[Debug::INSETS] << "MAYBE" << endl;
313 return the_locking_inset->LockInsetInInset(bv, inset);
315 lyxerr[Debug::INSETS] << "NOT OK" << endl;
319 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
322 if (!the_locking_inset)
324 if (the_locking_inset == inset) {
325 the_locking_inset->InsetUnlock(bv);
326 the_locking_inset = 0;
328 moveRight(bv, false);
331 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
332 if ((inset->LyxCode() == TABULAR_CODE) &&
333 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
335 UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
343 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
345 if (!the_locking_inset)
347 if (the_locking_inset != inset)
348 return the_locking_inset->UpdateInsetInInset(bv, inset);
354 int InsetTabular::InsetInInsetY()
356 if (!the_locking_inset)
359 return (inset_y + the_locking_inset->InsetInInsetY());
363 UpdatableInset * InsetTabular::GetLockingInset()
365 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
369 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
373 if (the_locking_inset)
374 return the_locking_inset->GetFirstLockingInsetOfType(c);
379 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
381 if (the_locking_inset)
382 return the_locking_inset->InsertInset(bv, inset);
387 void InsetTabular::InsetButtonRelease(BufferView * bv,
388 int x, int y, int button)
391 if (the_locking_inset) {
393 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
394 i->InsetButtonRelease(bv, x, y, button);
398 MenuLayoutTabular(true, this);
401 if (the_locking_inset) {
402 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
405 no_selection = false;
409 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
411 if (hasCharSelection()) {
412 sel_pos_start = sel_pos_end = 0;
413 UpdateLocal(bv, false);
415 no_selection = false;
419 setPos(bv->painter(), x, y);
421 bool inset_hit = InsetHit(bv, x, y);
423 if ((ocell == actcell) && the_locking_inset && inset_hit) {
424 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
426 } else if (the_locking_inset) {
427 the_locking_inset->InsetUnlock(bv);
429 the_locking_inset = 0;
430 sel_pos_start = sel_pos_end = cursor.pos;
431 sel_cell_start = sel_cell_end = actcell;
432 if (inset_hit && bv->the_locking_inset) {
433 ActivateCellInset(bv, x, y, button);
434 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
439 bview->getOwner()->getPopups().showFormTabular();
440 else if (ocell != actcell)
441 bview->getOwner()->getPopups().updateFormTabular();
446 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
448 if (the_locking_inset) {
449 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
450 y - inset_y, button);
454 // int ocell = actcell,
455 int old = sel_pos_end;
457 setPos(bv->painter(), x, y);
458 sel_pos_end = cursor.pos;
459 sel_cell_end = actcell;
460 if (old != sel_pos_end)
461 UpdateLocal(bv, false);
463 if (ocell != actcell)
464 bview->getOwner()->getPopups().updateFormTabular();
467 no_selection = false;
471 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
473 if (the_locking_inset) {
474 the_locking_inset->InsetKeyPress(xke);
480 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
483 UpdatableInset::RESULT
486 no_selection = false;
487 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
488 || (result == DISPATCHED_NOUPDATE)) {
490 resetPos(bv->painter());
495 if ((action < 0) && arg.empty())
498 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
499 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
501 if (the_locking_inset) {
502 result=the_locking_inset->LocalDispatch(bv, action, arg);
503 if (result == DISPATCHED_NOUPDATE)
505 else if (result == DISPATCHED) {
506 bool upd = SetCellDimensions(bv->painter(), actcell, actrow);
507 the_locking_inset->ToggleInsetCursor(bv);
508 UpdateLocal(bv, upd);
509 the_locking_inset->ToggleInsetCursor(bv);
511 } else if (result == FINISHED) {
512 if ((action == LFUN_RIGHT) || (action == -1)) {
513 cursor.pos = inset_pos + 1;
514 resetPos(bv->painter());
524 // Normal chars not handled here
527 // --- Cursor Movements ---------------------------------------------
529 moveRight(bv, false);
530 sel_pos_end = cursor.pos;
531 UpdateLocal(bv, false);
534 result = moveRight(bv);
535 if (hasCharSelection()) {
536 sel_pos_start = sel_pos_end = cursor.pos;
537 UpdateLocal(bv, false);
539 sel_pos_start = sel_pos_end = cursor.pos;
543 sel_pos_end = cursor.pos;
544 UpdateLocal(bv, false);
547 result = moveLeft(bv);
548 if (hasCharSelection()) {
549 sel_pos_start = sel_pos_end = cursor.pos;
550 UpdateLocal(bv, false);
552 sel_pos_start = sel_pos_end = cursor.pos;
556 sel_pos_end = cursor.pos;
557 UpdateLocal(bv, false);
561 if (hasCharSelection()) {
562 sel_pos_start = sel_pos_end = cursor.pos;
563 UpdateLocal(bv, false);
565 sel_pos_start = sel_pos_end = cursor.pos;
569 sel_pos_end = cursor.pos;
570 UpdateLocal(bv, false);
574 if (hasCharSelection()) {
575 sel_pos_start = sel_pos_end = cursor.pos;
576 UpdateLocal(bv, false);
578 sel_pos_start = sel_pos_end = cursor.pos;
589 if (hasCharSelection()) {
590 sel_pos_start = sel_pos_end = cursor.pos;
591 UpdateLocal(bv, false);
593 sel_pos_start = sel_pos_end = cursor.pos;
596 case LFUN_LAYOUT_TABLE:
598 int flag = (arg == "true");
599 MenuLayoutTabular(flag, this);
603 result = UNDISPATCHED;
606 if (result!=FINISHED) {
607 if (!the_locking_inset) {
609 if (ocell != actcell)
610 bview->getOwner()->getPopups().updateFormTabular();
615 bv->unlockInset(this);
620 int InsetTabular::Latex(ostream & os, bool fragile, bool fp) const
622 return tabular->Latex(os, fragile, fp);
626 int InsetTabular::Ascii(ostream &) const
631 int InsetTabular::Linuxdoc(ostream &) const
637 int InsetTabular::DocBook(ostream &) const
643 void InsetTabular::Validate(LaTeXFeatures & features) const
645 if (tabular->IsLongTabular())
646 features.longtable = true;
650 void InsetTabular::calculate_width_of_cells(Painter & pain,
651 LyXFont const & font) const
657 for(int i = 0; i < tabular->rows(); ++i) {
658 maxAsc = maxDesc = 0;
659 for(int j= 0; j < tabular->columns(); ++j) {
660 if (tabular->IsPartOfMultiColumn(i,j))
663 inset = tabular->GetCellInset(cell);
664 maxAsc = max(maxAsc, inset->ascent(pain, font));
665 maxDesc = max(maxDesc, inset->descent(pain, font));
666 tabular->SetWidthOfCell(cell, inset->width(pain, font));
668 tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
669 tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
674 void InsetTabular::GetCursorPos(int & x, int & y) const
681 void InsetTabular::ToggleInsetCursor(BufferView * bv)
683 if (the_locking_inset) {
684 the_locking_inset->ToggleInsetCursor(bv);
688 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
690 int asc = lyxfont::maxAscent(font);
691 int desc = lyxfont::maxDescent(font);
694 bv->hideLockedInsetCursor();
696 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
697 cursor_visible = !cursor_visible;
701 void InsetTabular::ShowInsetCursor(BufferView * bv)
703 if (!cursor_visible) {
704 LyXFont font; // = GetFont(par, cursor.pos);
706 int asc = lyxfont::maxAscent(font);
707 int desc = lyxfont::maxDescent(font);
708 bv->fitLockedInsetCursor(cursor.x, cursor.y, asc, desc);
709 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
710 cursor_visible = true;
715 void InsetTabular::HideInsetCursor(BufferView * bv)
718 ToggleInsetCursor(bv);
722 void InsetTabular::setPos(Painter & pain, int x, int y) const
724 cursor.y = cursor.pos = actcell = actrow = actcol = 0;
725 int ly = tabular->GetDescentOfRow(actrow);
727 // first search the right row
728 while((ly < y) && (actrow < tabular->rows())) {
729 cursor.y += tabular->GetDescentOfRow(actrow) +
730 tabular->GetAscentOfRow(actrow+1) +
731 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow+1,
734 ly = cursor.y + tabular->GetDescentOfRow(actrow);
736 actcell = tabular->GetCellNumber(actrow, actcol);
738 // now search the right column
739 int lx = tabular->GetWidthOfColumn(actcell) -
740 tabular->GetAdditionalWidth(actcell);
741 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
742 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
743 tabular->GetAdditionalWidth(actcell-1));
744 cursor.pos = ((actcell+1) * 2) - 1;
746 if ((lx - (tabular->GetWidthOfColumn(actcell)/2)) < x) {
747 cursor.x = lx + top_x - 2;
750 cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
755 int InsetTabular::getCellXPos(int cell) const
759 for(c=cell;!tabular->IsFirstCellInRow(c);--c)
761 int lx = tabular->GetWidthOfColumn(cell);
762 for(; (c < cell); ++c) {
763 lx += tabular->GetWidthOfColumn(c);
765 return (lx - tabular->GetWidthOfColumn(cell) + top_x +
766 ADD_TO_TABULAR_WIDTH);
769 void InsetTabular::resetPos(Painter & pain) const
773 actcol = tabular->column_of_cell(actcell);
776 actrow = cursor.y = 0;
777 for(; (cell<actcell) && !tabular->IsLastRow(cell); ++cell) {
778 if (tabular->IsLastCellInRow(cell)) {
779 cursor.y += tabular->GetDescentOfRow(actrow) +
780 tabular->GetAscentOfRow(actrow+1) +
781 tabular->GetAdditionalHeight(cell+1);
785 cursor.x = getCellXPos(actcell) + 2;
786 if (cursor.pos % 2) {
787 LyXFont font(LyXFont::ALL_SANE);
788 cursor.x += tabular->GetCellInset(actcell)->width(pain,font) +
789 tabular->GetBeginningOfTextInCell(actcell);
791 if ((!the_locking_inset ||
792 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
793 (actcell != oldcell)) {
794 UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
800 bool InsetTabular::SetCellDimensions(Painter & pain, int cell, int row)
802 InsetText * inset = tabular->GetCellInset(cell);
803 LyXFont font(LyXFont::ALL_SANE);
804 int asc = inset->ascent(pain, font) + ADD_TO_HEIGHT;
805 int desc = inset->descent(pain, font) + ADD_TO_HEIGHT;
806 int maxAsc = tabular->GetAscentOfRow(row);
807 int maxDesc = tabular->GetDescentOfRow(row);
808 bool ret = tabular->SetWidthOfCell(cell, inset->width(pain, font));
812 tabular->SetAscentOfRow(row, asc);
814 if (maxDesc < desc) {
816 tabular->SetDescentOfRow(row, desc);
822 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
824 if (cursor.pos % 2) { // behind the inset
826 if (actcell >= tabular->GetNumberOfCells())
830 if (ActivateCellInset(bv))
832 } else { // before the inset
835 resetPos(bv->painter());
836 return DISPATCHED_NOUPDATE;
840 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
845 if (cursor.pos % 2) { // behind the inset
847 } else if (lock) { // behind the inset
848 if (ActivateCellInset(bv, 0, 0, 0, true))
851 resetPos(bv->painter());
852 return DISPATCHED_NOUPDATE;
856 UpdatableInset::RESULT InsetTabular::moveUp()
858 return DISPATCHED_NOUPDATE;
862 UpdatableInset::RESULT InsetTabular::moveDown()
864 return DISPATCHED_NOUPDATE;
868 bool InsetTabular::moveNextCell()
874 bool InsetTabular::movePrevCell()
880 bool InsetTabular::Delete()
886 void InsetTabular::SetFont(BufferView *, LyXFont const &, bool)
891 void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val)
898 setAlign = LYX_ALIGN_LEFT,
904 case LyXTabular::ALIGN_LEFT:
905 setAlign=LYX_ALIGN_LEFT;
907 case LyXTabular::ALIGN_RIGHT:
908 setAlign=LYX_ALIGN_RIGHT;
910 case LyXTabular::ALIGN_CENTER:
911 setAlign=LYX_ALIGN_CENTER;
916 if (hasCellSelection()) {
917 if (sel_cell_start > sel_cell_end) {
918 sel_start = sel_cell_end;
919 sel_end = sel_cell_start;
921 sel_start = sel_cell_start;
922 sel_end = sel_cell_end;
925 sel_start = sel_end = actcell;
927 case LyXTabular::SET_PWIDTH:
929 bool update = tabular->GetPWidth(actcell).empty();
930 tabular->SetPWidth(actcell,val);
931 if (tabular->GetPWidth(actcell).empty() != update)
932 UpdateLocal(bv, true);
935 case LyXTabular::SET_SPECIAL_COLUMN:
936 case LyXTabular::SET_SPECIAL_MULTI:
937 tabular->SetAlignSpecial(actcell,val,feature);
939 case LyXTabular::APPEND_ROW:
941 // append the row into the tabular
942 tabular->AppendRow(actcell);
943 UpdateLocal(bv, true);
946 case LyXTabular::APPEND_COLUMN:
948 // append the column into the tabular
949 tabular->AppendColumn(actcell);
950 UpdateLocal(bv, true);
953 case LyXTabular::DELETE_ROW:
955 UpdateLocal(bv, true);
957 case LyXTabular::DELETE_COLUMN:
959 /* delete the column from the tabular */
960 tabular->DeleteColumn(actcell);
961 UpdateLocal(bv, true);
964 case LyXTabular::TOGGLE_LINE_TOP:
965 lineSet = !tabular->TopLine(actcell);
966 for(i=sel_start; i<=sel_end; ++i)
967 tabular->SetTopLine(i,lineSet);
968 UpdateLocal(bv, true);
971 case LyXTabular::TOGGLE_LINE_BOTTOM:
972 lineSet = !tabular->BottomLine(actcell);
973 for(i=sel_start; i<=sel_end; ++i)
974 tabular->SetBottomLine(i,lineSet);
975 UpdateLocal(bv, true);
978 case LyXTabular::TOGGLE_LINE_LEFT:
979 lineSet = !tabular->LeftLine(actcell);
980 for(i=sel_start; i<=sel_end; ++i)
981 tabular->SetLeftLine(i,lineSet);
982 UpdateLocal(bv, true);
985 case LyXTabular::TOGGLE_LINE_RIGHT:
986 lineSet = !tabular->RightLine(actcell);
987 for(i=sel_start; i<=sel_end; ++i)
988 tabular->SetRightLine(i,lineSet);
989 UpdateLocal(bv, true);
991 case LyXTabular::ALIGN_LEFT:
992 case LyXTabular::ALIGN_RIGHT:
993 case LyXTabular::ALIGN_CENTER:
994 for(i=sel_start; i<=sel_end; ++i)
995 tabular->SetAlignment(i,setAlign);
996 UpdateLocal(bv, true);
998 case LyXTabular::MULTICOLUMN:
1000 if (tabular->row_of_cell(sel_start) !=
1001 tabular->row_of_cell(sel_end)) {
1002 WriteAlert(_("Impossible Operation!"),
1003 _("Multicolumns can only be horizontally."),
1007 // just multicol for one Single Cell
1008 if (!hasCellSelection()) {
1009 // check wether we are completly in a multicol
1010 if (tabular->IsMultiColumn(actcell)) {
1011 tabular->UnsetMultiColumn(actcell);
1012 UpdateLocal(bv, true);
1014 tabular->SetMultiColumn(actcell, 1);
1015 UpdateLocal(bv, false);
1019 // we have a selection so this means we just add all this
1020 // cells to form a multicolumn cell
1024 if (sel_start > sel_end) {
1028 s_start = sel_start;
1031 tabular->SetMultiColumn(s_start, s_end);
1032 cursor.pos = s_start;
1033 sel_cell_end = sel_cell_start;
1034 UpdateLocal(bv, true);
1037 case LyXTabular::SET_ALL_LINES:
1039 case LyXTabular::UNSET_ALL_LINES:
1040 for(i=sel_start; i<=sel_end; ++i)
1041 tabular->SetAllLines(i, setLines);
1042 UpdateLocal(bv, true);
1044 case LyXTabular::SET_LONGTABULAR:
1045 tabular->SetLongTabular(true);
1046 UpdateLocal(bv, true); // because this toggles displayed
1048 case LyXTabular::UNSET_LONGTABULAR:
1049 tabular->SetLongTabular(false);
1050 UpdateLocal(bv, true); // because this toggles displayed
1052 case LyXTabular::SET_ROTATE_TABULAR:
1053 tabular->SetRotateTabular(true);
1055 case LyXTabular::UNSET_ROTATE_TABULAR:
1056 tabular->SetRotateTabular(false);
1058 case LyXTabular::SET_ROTATE_CELL:
1059 for(i=sel_start; i<=sel_end; ++i)
1060 tabular->SetRotateCell(i,true);
1062 case LyXTabular::UNSET_ROTATE_CELL:
1063 for(i=sel_start; i<=sel_end; ++i)
1064 tabular->SetRotateCell(i,false);
1066 case LyXTabular::SET_LINEBREAKS:
1067 what = !tabular->GetLinebreaks(actcell);
1068 for(i=sel_start; i<=sel_end; ++i)
1069 tabular->SetLinebreaks(i,what);
1071 case LyXTabular::SET_LTFIRSTHEAD:
1072 tabular->SetLTHead(actcell,true);
1074 case LyXTabular::SET_LTHEAD:
1075 tabular->SetLTHead(actcell,false);
1077 case LyXTabular::SET_LTFOOT:
1078 tabular->SetLTFoot(actcell,false);
1080 case LyXTabular::SET_LTLASTFOOT:
1081 tabular->SetLTFoot(actcell,true);
1083 case LyXTabular::SET_LTNEWPAGE:
1084 what = !tabular->GetLTNewPage(actcell);
1085 tabular->SetLTNewPage(actcell,what);
1090 void InsetTabular::RemoveTabularRow()
1094 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1097 // the cursor.pos has to be before the inset so if it isn't now just
1098 // reset the curor pos first!
1099 if (cursor.pos % 2) { // behind the inset
1101 resetPos(bv->painter());
1103 UpdatableInset * inset =
1104 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1105 LyXFont font(LyXFont::ALL_SANE);
1107 x = inset->x() + inset->width(bv->painter(), font);
1108 y = inset->descent(bv->painter(), font);
1110 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
1112 inset->Edit(bv, x-inset_x, y-inset_y, button);
1113 if (!the_locking_inset)
1115 UpdateLocal(bv, true);
1119 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1121 InsetText * inset = tabular->GetCellInset(actcell);
1124 if (cursor.pos % 2) { // behind the inset
1125 return (((x+top_x) < cursor.x) &&
1126 ((x+top_x) > (cursor.x - inset->width(bv->painter(),
1127 LyXFont(LyXFont::ALL_SANE)))));
1129 int x2 = cursor.x + tabular->GetBeginningOfTextInCell(actcell);
1130 return ((x1 > x2) &&
1131 (x1 < (x2 + inset->width(bv->painter(),
1132 LyXFont(LyXFont::ALL_SANE)))));
1136 // This returns paperWidth() if the cell-width is unlimited or the width
1137 // in pixels if we have a pwidth for this cell.
1138 int InsetTabular::GetMaxWidthOfCell(Painter & pain, int cell) const
1142 if ((w=tabular->GetPWidth(cell)).empty())
1143 return pain.paperWidth();
1144 return VSpace(w).inPixels( 0, 0);
1147 int InsetTabular::getMaxWidth(Painter & pain,
1148 UpdatableInset const * inset) const
1151 int n = tabular->GetNumberOfCells();
1152 for(cell=0; cell < n; ++cell) {
1153 if (tabular->GetCellInset(cell) == inset)
1157 return pain.paperWidth();
1158 int w = GetMaxWidthOfCell(pain, cell);
1159 // this because text insets remove the xpos from the maxwidth because
1160 // otherwise the would not break good!!!
1161 // w += getCellXPos(cell) + tabular->GetBeginningOfTextInCell(cell);
1166 void InsetTabular::recomputeTextInsets(Painter & pain, const LyXFont & font) const
1172 for(int j= 0; j < tabular->columns(); ++j) {
1173 for(int i = 0; i < tabular->rows(); ++i) {
1174 if (tabular->IsPartOfMultiColumn(i,j))
1176 cell = tabular->GetCellNumber(i,j);
1177 inset = tabular->GetCellInset(cell);
1178 inset->computeTextRows(pain);
1179 tabular->SetWidthOfCell(cell, inset->width(pain, font));
1181 cell = tabular->GetCellNumber(0, j);
1182 cx += tabular->GetWidthOfColumn(cell);