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);
112 token = lex.GetString();
113 while (lex.IsOK() && (token != "\\end_inset")) {
115 token = lex.GetString();
117 if (token != "\\end_inset") {
118 lex.printError("Missing \\end_inset at this point. "
125 int InsetTabular::ascent(Painter & pain, LyXFont const & font) const
128 calculate_width_of_cells(pain, font);
131 return tabular->GetAscentOfRow(0);
135 int InsetTabular::descent(Painter & pain, LyXFont const & font) const
138 calculate_width_of_cells(pain, font);
141 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0);
145 int InsetTabular::width(Painter & pain, LyXFont const & font) const
148 calculate_width_of_cells(pain, font);
151 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
155 void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline,
163 UpdatableInset::draw(pain,font,baseline,x);
164 if (init_inset || (top_x != int(x)) || (top_baseline != baseline)) {
168 top_baseline = baseline;
170 recomputeTextInsets(pain, font);
171 calculate_width_of_cells(pain, font);
175 x += ADD_TO_TABULAR_WIDTH;
176 for(i=0;i<tabular->rows();++i) {
178 for(j=0;j<tabular->columns();++j) {
179 if (tabular->IsPartOfMultiColumn(i,j))
181 cx = nx + tabular->GetBeginningOfTextInCell(cell);
182 tabular->GetCellInset(cell)->draw(pain, font, baseline, cx);
183 DrawCellLines(pain, nx, baseline, i, cell);
184 nx += tabular->GetWidthOfColumn(cell);
187 baseline += tabular->GetDescentOfRow(i) + tabular->GetAscentOfRow(i+1)
188 + tabular->GetAdditionalHeight(cell+1);
190 x += width(pain, font);
194 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
195 int row, int cell) const
197 int x2 = x + tabular->GetWidthOfColumn(cell);
200 if (!tabular->TopAlreadyDrawed(cell)) {
201 on_off = !tabular->TopLine(cell);
202 pain.line(x, baseline - tabular->GetAscentOfRow(row),
203 x2, baseline - tabular->GetAscentOfRow(row),
204 on_off ? LColor::tabularonoffline:LColor::tabularline,
205 on_off ? Painter::line_onoffdash:Painter::line_solid);
207 on_off = !tabular->BottomLine(cell);
208 pain.line(x,baseline + tabular->GetDescentOfRow(row),
209 x2, baseline + tabular->GetDescentOfRow(row),
210 on_off ? LColor::tabularonoffline:LColor::tabularline,
211 on_off ? Painter::line_onoffdash:Painter::line_solid);
212 if (!tabular->LeftAlreadyDrawed(cell)) {
213 on_off = !tabular->LeftLine(cell);
214 pain.line(x, baseline - tabular->GetAscentOfRow(row),
215 x, baseline + tabular->GetDescentOfRow(row),
216 on_off ? LColor::tabularonoffline:LColor::tabularline,
217 on_off ? Painter::line_onoffdash:Painter::line_solid);
219 on_off = !tabular->RightLine(cell);
220 pain.line(x2 - tabular->GetAdditionalWidth(cell),
221 baseline - tabular->GetAscentOfRow(row),
222 x2 - tabular->GetAdditionalWidth(cell),
223 baseline + tabular->GetDescentOfRow(row),
224 on_off ? LColor::tabularonoffline:LColor::tabularline,
225 on_off ? Painter::line_onoffdash:Painter::line_solid);
229 char const * InsetTabular::EditMessage() const
231 return _("Opened Tabular Inset");
235 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
237 UpdatableInset::Edit(bv, x, y, button);
239 if (!bv->lockInset(this)) {
240 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
244 the_locking_inset = 0;
245 sel_pos_start = sel_pos_end = inset_pos = inset_x = inset_y = 0;
246 setPos(bv->painter(), x, y);
247 sel_pos_start = sel_pos_end = cursor.pos;
248 bv->text->FinishUndo();
249 if (InsetHit(bv, x, y)) {
250 ActivateCellInset(bv, x, y, button);
252 UpdateLocal(bv, true);
253 // bv->getOwner()->getPopups().updateFormTabular();
257 void InsetTabular::InsetUnlock(BufferView * bv)
260 if (the_locking_inset) {
261 the_locking_inset->InsetUnlock(bv);
262 the_locking_inset = 0;
265 if (hasCharSelection()) {
266 sel_pos_start = sel_pos_end = cursor.pos;
267 UpdateLocal(bv, false);
269 sel_pos_start = sel_pos_end = cursor.pos;
270 no_selection = false;
275 void InsetTabular::UpdateLocal(BufferView * bv, bool flag)
278 calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE));
279 bv->updateInset(this, flag);
281 resetPos(bv->painter());
284 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
286 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
290 if (inset == tabular->GetCellInset(actcell)) {
291 lyxerr[Debug::INSETS] << "OK" << endl;
292 the_locking_inset = tabular->GetCellInset(actcell);
293 resetPos(bv->painter());
294 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
296 inset_pos = cursor.pos;
298 } else if (the_locking_inset && (the_locking_inset == inset)) {
299 if (cursor.pos == inset_pos) {
300 lyxerr[Debug::INSETS] << "OK" << endl;
301 resetPos(bv->painter());
302 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
305 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
307 } else if (the_locking_inset) {
308 lyxerr[Debug::INSETS] << "MAYBE" << endl;
309 return the_locking_inset->LockInsetInInset(bv, inset);
311 lyxerr[Debug::INSETS] << "NOT OK" << endl;
315 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
318 if (!the_locking_inset)
320 if (the_locking_inset == inset) {
321 the_locking_inset->InsetUnlock(bv);
322 the_locking_inset = 0;
324 moveRight(bv, false);
327 if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
328 if ((inset->LyxCode() == TABULAR_CODE) &&
329 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
331 UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
339 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
341 if (!the_locking_inset)
343 if (the_locking_inset != inset)
344 return the_locking_inset->UpdateInsetInInset(bv, inset);
350 int InsetTabular::InsetInInsetY()
352 if (!the_locking_inset)
355 return (inset_y + the_locking_inset->InsetInInsetY());
359 UpdatableInset * InsetTabular::GetLockingInset()
361 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
365 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
369 if (the_locking_inset)
370 return the_locking_inset->GetFirstLockingInsetOfType(c);
375 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
377 if (the_locking_inset)
378 return the_locking_inset->InsertInset(bv, inset);
383 void InsetTabular::InsetButtonRelease(BufferView * bv,
384 int x, int y, int button)
387 if (the_locking_inset) {
389 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
390 i->InsetButtonRelease(bv, x, y, button);
394 MenuLayoutTabular(true, this);
397 if (the_locking_inset) {
398 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
401 no_selection = false;
405 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
407 if (hasCharSelection()) {
408 sel_pos_start = sel_pos_end = 0;
409 UpdateLocal(bv, false);
411 no_selection = false;
415 setPos(bv->painter(), x, y);
417 bool inset_hit = InsetHit(bv, x, y);
419 if ((ocell == actcell) && the_locking_inset && inset_hit) {
420 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
422 } else if (the_locking_inset) {
423 the_locking_inset->InsetUnlock(bv);
425 the_locking_inset = 0;
426 sel_pos_start = sel_pos_end = cursor.pos;
427 sel_cell_start = sel_cell_end = actcell;
428 if (inset_hit && bv->the_locking_inset) {
429 ActivateCellInset(bv, x, y, button);
430 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
435 bview->getOwner()->getPopups().showFormTabular();
436 else if (ocell != actcell)
437 bview->getOwner()->getPopups().updateFormTabular();
442 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
444 if (the_locking_inset) {
445 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
446 y - inset_y, button);
450 // int ocell = actcell,
451 int old = sel_pos_end;
453 setPos(bv->painter(), x, y);
454 sel_pos_end = cursor.pos;
455 sel_cell_end = actcell;
456 if (old != sel_pos_end)
457 UpdateLocal(bv, false);
459 if (ocell != actcell)
460 bview->getOwner()->getPopups().updateFormTabular();
463 no_selection = false;
467 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
469 if (the_locking_inset) {
470 the_locking_inset->InsetKeyPress(xke);
476 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
479 UpdatableInset::RESULT
482 no_selection = false;
483 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
484 || (result == DISPATCHED_NOUPDATE)) {
486 resetPos(bv->painter());
491 if ((action < 0) && arg.empty())
494 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
495 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
497 if (the_locking_inset) {
498 result=the_locking_inset->LocalDispatch(bv, action, arg);
499 if (result == DISPATCHED_NOUPDATE)
501 else if (result == DISPATCHED) {
502 bool upd = SetCellDimensions(bv->painter(), actcell, actrow);
503 the_locking_inset->ToggleInsetCursor(bv);
504 UpdateLocal(bv, upd);
505 the_locking_inset->ToggleInsetCursor(bv);
507 } else if (result == FINISHED) {
508 if ((action == LFUN_RIGHT) || (action == -1)) {
509 cursor.pos = inset_pos + 1;
510 resetPos(bv->painter());
520 // Normal chars not handled here
523 // --- Cursor Movements ---------------------------------------------
525 moveRight(bv, false);
526 sel_pos_end = cursor.pos;
527 UpdateLocal(bv, false);
530 result = moveRight(bv);
531 if (hasCharSelection()) {
532 sel_pos_start = sel_pos_end = cursor.pos;
533 UpdateLocal(bv, false);
535 sel_pos_start = sel_pos_end = cursor.pos;
539 sel_pos_end = cursor.pos;
540 UpdateLocal(bv, false);
543 result = moveLeft(bv);
544 if (hasCharSelection()) {
545 sel_pos_start = sel_pos_end = cursor.pos;
546 UpdateLocal(bv, false);
548 sel_pos_start = sel_pos_end = cursor.pos;
552 sel_pos_end = cursor.pos;
553 UpdateLocal(bv, false);
557 if (hasCharSelection()) {
558 sel_pos_start = sel_pos_end = cursor.pos;
559 UpdateLocal(bv, false);
561 sel_pos_start = sel_pos_end = cursor.pos;
565 sel_pos_end = cursor.pos;
566 UpdateLocal(bv, false);
570 if (hasCharSelection()) {
571 sel_pos_start = sel_pos_end = cursor.pos;
572 UpdateLocal(bv, false);
574 sel_pos_start = sel_pos_end = cursor.pos;
585 if (hasCharSelection()) {
586 sel_pos_start = sel_pos_end = cursor.pos;
587 UpdateLocal(bv, false);
589 sel_pos_start = sel_pos_end = cursor.pos;
592 case LFUN_LAYOUT_TABLE:
594 int flag = (arg == "true");
595 MenuLayoutTabular(flag, this);
599 result = UNDISPATCHED;
602 if (result!=FINISHED) {
603 if (!the_locking_inset) {
605 if (ocell != actcell)
606 bview->getOwner()->getPopups().updateFormTabular();
611 bv->unlockInset(this);
616 int InsetTabular::Latex(ostream & os, bool fragile, bool fp) const
618 return tabular->Latex(os, fragile, fp);
622 int InsetTabular::Ascii(ostream &) const
627 int InsetTabular::Linuxdoc(ostream &) const
633 int InsetTabular::DocBook(ostream &) const
639 void InsetTabular::Validate(LaTeXFeatures & features) const
641 if (tabular->IsLongTabular())
642 features.longtable = true;
646 void InsetTabular::calculate_width_of_cells(Painter & pain,
647 LyXFont const & font) const
653 for(int i = 0; i < tabular->rows(); ++i) {
654 maxAsc = maxDesc = 0;
655 for(int j= 0; j < tabular->columns(); ++j) {
656 if (tabular->IsPartOfMultiColumn(i,j))
659 inset = tabular->GetCellInset(cell);
660 maxAsc = max(maxAsc, inset->ascent(pain, font));
661 maxDesc = max(maxDesc, inset->descent(pain, font));
662 tabular->SetWidthOfCell(cell, inset->width(pain, font));
664 tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
665 tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
670 void InsetTabular::GetCursorPos(int & x, int & y) const
677 void InsetTabular::ToggleInsetCursor(BufferView * bv)
679 if (the_locking_inset) {
680 the_locking_inset->ToggleInsetCursor(bv);
684 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
686 int asc = lyxfont::maxAscent(font);
687 int desc = lyxfont::maxDescent(font);
690 bv->hideLockedInsetCursor();
692 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
693 cursor_visible = !cursor_visible;
697 void InsetTabular::ShowInsetCursor(BufferView * bv)
699 if (!cursor_visible) {
700 LyXFont font; // = GetFont(par, cursor.pos);
702 int asc = lyxfont::maxAscent(font);
703 int desc = lyxfont::maxDescent(font);
704 bv->fitLockedInsetCursor(cursor.x, cursor.y, asc, desc);
705 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
706 cursor_visible = true;
711 void InsetTabular::HideInsetCursor(BufferView * bv)
714 ToggleInsetCursor(bv);
718 void InsetTabular::setPos(Painter & pain, int x, int y) const
720 cursor.y = cursor.pos = actcell = actrow = actcol = 0;
721 int ly = tabular->GetDescentOfRow(actrow);
723 // first search the right row
724 while((ly < y) && (actrow < tabular->rows())) {
725 cursor.y += tabular->GetDescentOfRow(actrow) +
726 tabular->GetAscentOfRow(actrow+1) +
727 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow+1,
730 ly = cursor.y + tabular->GetDescentOfRow(actrow);
732 actcell = tabular->GetCellNumber(actrow, actcol);
734 // now search the right column
735 int lx = tabular->GetWidthOfColumn(actcell) -
736 tabular->GetAdditionalWidth(actcell);
737 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
738 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
739 tabular->GetAdditionalWidth(actcell-1));
740 cursor.pos = ((actcell+1) * 2) - 1;
742 if ((lx - (tabular->GetWidthOfColumn(actcell)/2)) < x) {
743 cursor.x = lx + top_x - 2;
746 cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
751 int InsetTabular::getCellXPos(int cell) const
755 for(c=cell;!tabular->IsFirstCellInRow(c);--c)
757 int lx = tabular->GetWidthOfColumn(cell);
758 for(; (c < cell); ++c) {
759 lx += tabular->GetWidthOfColumn(c);
761 return (lx - tabular->GetWidthOfColumn(cell) + top_x +
762 ADD_TO_TABULAR_WIDTH);
765 void InsetTabular::resetPos(Painter & pain) const
769 actcol = tabular->column_of_cell(actcell);
772 actrow = cursor.y = 0;
773 for(; (cell<actcell) && !tabular->IsLastRow(cell); ++cell) {
774 if (tabular->IsLastCellInRow(cell)) {
775 cursor.y += tabular->GetDescentOfRow(actrow) +
776 tabular->GetAscentOfRow(actrow+1) +
777 tabular->GetAdditionalHeight(cell+1);
781 cursor.x = getCellXPos(actcell) + 2;
782 if (cursor.pos % 2) {
783 LyXFont font(LyXFont::ALL_SANE);
784 cursor.x += tabular->GetCellInset(actcell)->width(pain,font) +
785 tabular->GetBeginningOfTextInCell(actcell);
787 if ((!the_locking_inset ||
788 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
789 (actcell != oldcell)) {
790 UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
796 bool InsetTabular::SetCellDimensions(Painter & pain, int cell, int row)
798 InsetText * inset = tabular->GetCellInset(cell);
799 LyXFont font(LyXFont::ALL_SANE);
800 int asc = inset->ascent(pain, font) + ADD_TO_HEIGHT;
801 int desc = inset->descent(pain, font) + ADD_TO_HEIGHT;
802 int maxAsc = tabular->GetAscentOfRow(row);
803 int maxDesc = tabular->GetDescentOfRow(row);
804 bool ret = tabular->SetWidthOfCell(cell, inset->width(pain, font));
808 tabular->SetAscentOfRow(row, asc);
810 if (maxDesc < desc) {
812 tabular->SetDescentOfRow(row, desc);
818 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
820 if (cursor.pos % 2) { // behind the inset
822 if (actcell >= tabular->GetNumberOfCells())
826 if (ActivateCellInset(bv))
828 } else { // before the inset
831 resetPos(bv->painter());
832 return DISPATCHED_NOUPDATE;
836 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
841 if (cursor.pos % 2) { // behind the inset
843 } else if (lock) { // behind the inset
844 if (ActivateCellInset(bv, 0, 0, 0, true))
847 resetPos(bv->painter());
848 return DISPATCHED_NOUPDATE;
852 UpdatableInset::RESULT InsetTabular::moveUp()
854 return DISPATCHED_NOUPDATE;
858 UpdatableInset::RESULT InsetTabular::moveDown()
860 return DISPATCHED_NOUPDATE;
864 bool InsetTabular::moveNextCell()
870 bool InsetTabular::movePrevCell()
876 bool InsetTabular::Delete()
882 void InsetTabular::SetFont(BufferView *, LyXFont const &, bool)
887 void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val)
894 setAlign = LYX_ALIGN_LEFT,
900 case LyXTabular::ALIGN_LEFT:
901 setAlign=LYX_ALIGN_LEFT;
903 case LyXTabular::ALIGN_RIGHT:
904 setAlign=LYX_ALIGN_RIGHT;
906 case LyXTabular::ALIGN_CENTER:
907 setAlign=LYX_ALIGN_CENTER;
912 if (hasCellSelection()) {
913 if (sel_cell_start > sel_cell_end) {
914 sel_pos_start = sel_cell_end;
915 sel_pos_end = sel_cell_start;
917 sel_pos_start = sel_cell_start;
918 sel_pos_end = sel_cell_end;
921 sel_pos_start = sel_pos_end = actcell;
923 case LyXTabular::SET_PWIDTH:
925 bool update = tabular->GetPWidth(actcell).empty();
926 tabular->SetPWidth(actcell,val);
927 if (tabular->GetPWidth(actcell).empty() != update)
928 UpdateLocal(bv, true);
931 case LyXTabular::SET_SPECIAL_COLUMN:
932 case LyXTabular::SET_SPECIAL_MULTI:
933 tabular->SetAlignSpecial(actcell,val,feature);
935 case LyXTabular::APPEND_ROW:
937 // append the row into the tabular
938 tabular->AppendRow(actcell);
939 UpdateLocal(bv, true);
942 case LyXTabular::APPEND_COLUMN:
944 // append the column into the tabular
945 tabular->AppendColumn(actcell);
946 UpdateLocal(bv, true);
949 case LyXTabular::DELETE_ROW:
951 UpdateLocal(bv, true);
953 case LyXTabular::DELETE_COLUMN:
955 /* delete the column from the tabular */
956 tabular->DeleteColumn(actcell);
957 UpdateLocal(bv, true);
960 case LyXTabular::TOGGLE_LINE_TOP:
961 lineSet = !tabular->TopLine(actcell);
962 for(i=sel_pos_start; i<=sel_pos_end; ++i)
963 tabular->SetTopLine(i,lineSet);
964 UpdateLocal(bv, true);
967 case LyXTabular::TOGGLE_LINE_BOTTOM:
968 lineSet = !tabular->BottomLine(actcell);
969 for(i=sel_pos_start; i<=sel_pos_end; ++i)
970 tabular->SetBottomLine(i,lineSet);
971 UpdateLocal(bv, true);
974 case LyXTabular::TOGGLE_LINE_LEFT:
975 lineSet = !tabular->LeftLine(actcell);
976 for(i=sel_pos_start; i<=sel_pos_end; ++i)
977 tabular->SetLeftLine(i,lineSet);
978 UpdateLocal(bv, true);
981 case LyXTabular::TOGGLE_LINE_RIGHT:
982 lineSet = !tabular->RightLine(actcell);
983 for(i=sel_pos_start; i<=sel_pos_end; ++i)
984 tabular->SetRightLine(i,lineSet);
985 UpdateLocal(bv, true);
987 case LyXTabular::ALIGN_LEFT:
988 case LyXTabular::ALIGN_RIGHT:
989 case LyXTabular::ALIGN_CENTER:
990 for(i=sel_pos_start; i<=sel_pos_end; ++i)
991 tabular->SetAlignment(i,setAlign);
992 UpdateLocal(bv, true);
994 case LyXTabular::MULTICOLUMN:
996 if (tabular->row_of_cell(sel_pos_start) !=
997 tabular->row_of_cell(sel_pos_end)) {
998 WriteAlert(_("Impossible Operation!"),
999 _("Multicolumns can only be horizontally."),
1003 // just multicol for one Single Cell
1004 if (!hasCellSelection()) {
1005 // check wether we are completly in a multicol
1006 if (tabular->IsMultiColumn(actcell)) {
1007 tabular->UnsetMultiColumn(actcell);
1008 UpdateLocal(bv, true);
1010 tabular->SetMultiColumn(actcell, 1);
1011 UpdateLocal(bv, false);
1015 // we have a selection so this means we just add all this
1016 // cells to form a multicolumn cell
1020 if (sel_pos_start > sel_pos_end) {
1021 s_start = sel_pos_end;
1022 s_end = sel_pos_start;
1024 s_start = sel_pos_start;
1025 s_end = sel_pos_end;
1027 tabular->SetMultiColumn(s_start, s_end);
1028 cursor.pos = s_start;
1029 sel_cell_end = sel_cell_start;
1030 UpdateLocal(bv, true);
1033 case LyXTabular::SET_ALL_LINES:
1035 case LyXTabular::UNSET_ALL_LINES:
1036 for(i=sel_pos_start; i<=sel_pos_end; ++i)
1037 tabular->SetAllLines(i, setLines);
1038 UpdateLocal(bv, true);
1040 case LyXTabular::SET_LONGTABULAR:
1041 tabular->SetLongTabular(true);
1042 UpdateLocal(bv, true); // because this toggles displayed
1044 case LyXTabular::UNSET_LONGTABULAR:
1045 tabular->SetLongTabular(false);
1046 UpdateLocal(bv, true); // because this toggles displayed
1048 case LyXTabular::SET_ROTATE_TABULAR:
1049 tabular->SetRotateTabular(true);
1051 case LyXTabular::UNSET_ROTATE_TABULAR:
1052 tabular->SetRotateTabular(false);
1054 case LyXTabular::SET_ROTATE_CELL:
1055 for(i=sel_pos_start; i<=sel_pos_end; ++i)
1056 tabular->SetRotateCell(i,true);
1058 case LyXTabular::UNSET_ROTATE_CELL:
1059 for(i=sel_pos_start; i<=sel_pos_end; ++i)
1060 tabular->SetRotateCell(i,false);
1062 case LyXTabular::SET_LINEBREAKS:
1063 what = !tabular->GetLinebreaks(actcell);
1064 for(i=sel_pos_start; i<=sel_pos_end; ++i)
1065 tabular->SetLinebreaks(i,what);
1067 case LyXTabular::SET_LTFIRSTHEAD:
1068 tabular->SetLTHead(actcell,true);
1070 case LyXTabular::SET_LTHEAD:
1071 tabular->SetLTHead(actcell,false);
1073 case LyXTabular::SET_LTFOOT:
1074 tabular->SetLTFoot(actcell,false);
1076 case LyXTabular::SET_LTLASTFOOT:
1077 tabular->SetLTFoot(actcell,true);
1079 case LyXTabular::SET_LTNEWPAGE:
1080 what = !tabular->GetLTNewPage(actcell);
1081 tabular->SetLTNewPage(actcell,what);
1086 void InsetTabular::RemoveTabularRow()
1090 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1093 // the cursor.pos has to be before the inset so if it isn't now just
1094 // reset the curor pos first!
1095 if (cursor.pos % 2) { // behind the inset
1097 resetPos(bv->painter());
1099 UpdatableInset * inset =
1100 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1101 LyXFont font(LyXFont::ALL_SANE);
1103 x = inset->x() + inset->width(bv->painter(), font);
1104 y = inset->descent(bv->painter(), font);
1106 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
1108 inset->Edit(bv, x-inset_x, y-inset_y, button);
1109 if (!the_locking_inset)
1111 UpdateLocal(bv, true);
1115 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1117 InsetText * inset = tabular->GetCellInset(actcell);
1120 if (cursor.pos % 2) { // behind the inset
1121 return (((x+top_x) < cursor.x) &&
1122 ((x+top_x) > (cursor.x - inset->width(bv->painter(),
1123 LyXFont(LyXFont::ALL_SANE)))));
1125 int x2 = cursor.x + tabular->GetBeginningOfTextInCell(actcell);
1126 return ((x1 > x2) &&
1127 (x1 < (x2 + inset->width(bv->painter(),
1128 LyXFont(LyXFont::ALL_SANE)))));
1132 // This returns paperWidth() if the cell-width is unlimited or the width
1133 // in pixels if we have a pwidth for this cell.
1134 int InsetTabular::GetMaxWidthOfCell(Painter & pain, int cell) const
1138 if ((w=tabular->GetPWidth(cell)).empty())
1139 return pain.paperWidth();
1140 return VSpace(w).inPixels( 0, 0);
1143 int InsetTabular::getMaxWidth(Painter & pain,
1144 UpdatableInset const * inset) const
1147 int n = tabular->GetNumberOfCells();
1148 for(cell=0; cell < n; ++cell) {
1149 if (tabular->GetCellInset(cell) == inset)
1153 return pain.paperWidth();
1154 int w = GetMaxWidthOfCell(pain, cell);
1155 // this because text insets remove the xpos from the maxwidth because
1156 // otherwise the would not break good!!!
1157 // w += getCellXPos(cell) + tabular->GetBeginningOfTextInCell(cell);
1162 void InsetTabular::recomputeTextInsets(Painter & pain, const LyXFont & font) const
1168 for(int j= 0; j < tabular->columns(); ++j) {
1169 for(int i = 0; i < tabular->rows(); ++i) {
1170 if (tabular->IsPartOfMultiColumn(i,j))
1172 cell = tabular->GetCellNumber(i,j);
1173 inset = tabular->GetCellInset(cell);
1174 inset->computeTextRows(pain);
1175 tabular->SetWidthOfCell(cell, inset->width(pain, font));
1177 cell = tabular->GetCellNumber(0, j);
1178 cx += tabular->GetWidthOfColumn(cell);