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 tabular->Validate(features);
649 void InsetTabular::calculate_width_of_cells(Painter & pain,
650 LyXFont const & font) const
656 for(int i = 0; i < tabular->rows(); ++i) {
657 maxAsc = maxDesc = 0;
658 for(int j= 0; j < tabular->columns(); ++j) {
659 if (tabular->IsPartOfMultiColumn(i,j))
662 inset = tabular->GetCellInset(cell);
663 maxAsc = max(maxAsc, inset->ascent(pain, font));
664 maxDesc = max(maxDesc, inset->descent(pain, font));
665 tabular->SetWidthOfCell(cell, inset->width(pain, font));
667 tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
668 tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
673 void InsetTabular::GetCursorPos(int & x, int & y) const
680 void InsetTabular::ToggleInsetCursor(BufferView * bv)
682 if (the_locking_inset) {
683 the_locking_inset->ToggleInsetCursor(bv);
687 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
689 int asc = lyxfont::maxAscent(font);
690 int desc = lyxfont::maxDescent(font);
693 bv->hideLockedInsetCursor();
695 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
696 cursor_visible = !cursor_visible;
700 void InsetTabular::ShowInsetCursor(BufferView * bv)
702 if (!cursor_visible) {
703 LyXFont font; // = GetFont(par, cursor.pos);
705 int asc = lyxfont::maxAscent(font);
706 int desc = lyxfont::maxDescent(font);
707 bv->fitLockedInsetCursor(cursor.x, cursor.y, asc, desc);
708 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
709 cursor_visible = true;
714 void InsetTabular::HideInsetCursor(BufferView * bv)
717 ToggleInsetCursor(bv);
721 void InsetTabular::setPos(Painter & pain, int x, int y) const
723 cursor.y = cursor.pos = actcell = actrow = actcol = 0;
724 int ly = tabular->GetDescentOfRow(actrow);
726 // first search the right row
727 while((ly < y) && (actrow < tabular->rows())) {
728 cursor.y += tabular->GetDescentOfRow(actrow) +
729 tabular->GetAscentOfRow(actrow+1) +
730 tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow+1,
733 ly = cursor.y + tabular->GetDescentOfRow(actrow);
735 actcell = tabular->GetCellNumber(actrow, actcol);
737 // now search the right column
738 int lx = tabular->GetWidthOfColumn(actcell) -
739 tabular->GetAdditionalWidth(actcell);
740 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
741 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
742 tabular->GetAdditionalWidth(actcell-1));
743 cursor.pos = ((actcell+1) * 2) - 1;
745 if ((lx - (tabular->GetWidthOfColumn(actcell)/2)) < x) {
746 cursor.x = lx + top_x - 2;
749 cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
754 int InsetTabular::getCellXPos(int cell) const
758 for(c=cell;!tabular->IsFirstCellInRow(c);--c)
760 int lx = tabular->GetWidthOfColumn(cell);
761 for(; (c < cell); ++c) {
762 lx += tabular->GetWidthOfColumn(c);
764 return (lx - tabular->GetWidthOfColumn(cell) + top_x +
765 ADD_TO_TABULAR_WIDTH);
768 void InsetTabular::resetPos(Painter & pain) const
772 actcol = tabular->column_of_cell(actcell);
775 actrow = cursor.y = 0;
776 for(; (cell<actcell) && !tabular->IsLastRow(cell); ++cell) {
777 if (tabular->IsLastCellInRow(cell)) {
778 cursor.y += tabular->GetDescentOfRow(actrow) +
779 tabular->GetAscentOfRow(actrow+1) +
780 tabular->GetAdditionalHeight(cell+1);
784 cursor.x = getCellXPos(actcell) + 2;
785 if (cursor.pos % 2) {
786 LyXFont font(LyXFont::ALL_SANE);
787 cursor.x += tabular->GetCellInset(actcell)->width(pain,font) +
788 tabular->GetBeginningOfTextInCell(actcell);
790 if ((!the_locking_inset ||
791 !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
792 (actcell != oldcell)) {
793 UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
799 bool InsetTabular::SetCellDimensions(Painter & pain, int cell, int row)
801 InsetText * inset = tabular->GetCellInset(cell);
802 LyXFont font(LyXFont::ALL_SANE);
803 int asc = inset->ascent(pain, font) + ADD_TO_HEIGHT;
804 int desc = inset->descent(pain, font) + ADD_TO_HEIGHT;
805 int maxAsc = tabular->GetAscentOfRow(row);
806 int maxDesc = tabular->GetDescentOfRow(row);
807 bool ret = tabular->SetWidthOfCell(cell, inset->width(pain, font));
811 tabular->SetAscentOfRow(row, asc);
813 if (maxDesc < desc) {
815 tabular->SetDescentOfRow(row, desc);
821 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
823 if (cursor.pos % 2) { // behind the inset
825 if (actcell >= tabular->GetNumberOfCells())
829 if (ActivateCellInset(bv))
831 } else { // before the inset
834 resetPos(bv->painter());
835 return DISPATCHED_NOUPDATE;
839 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
844 if (cursor.pos % 2) { // behind the inset
846 } else if (lock) { // behind the inset
847 if (ActivateCellInset(bv, 0, 0, 0, true))
850 resetPos(bv->painter());
851 return DISPATCHED_NOUPDATE;
855 UpdatableInset::RESULT InsetTabular::moveUp()
857 return DISPATCHED_NOUPDATE;
861 UpdatableInset::RESULT InsetTabular::moveDown()
863 return DISPATCHED_NOUPDATE;
867 bool InsetTabular::moveNextCell()
873 bool InsetTabular::movePrevCell()
879 bool InsetTabular::Delete()
885 void InsetTabular::SetFont(BufferView *, LyXFont const &, bool)
890 void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val)
897 setAlign = LYX_ALIGN_LEFT,
903 case LyXTabular::ALIGN_LEFT:
904 setAlign=LYX_ALIGN_LEFT;
906 case LyXTabular::ALIGN_RIGHT:
907 setAlign=LYX_ALIGN_RIGHT;
909 case LyXTabular::ALIGN_CENTER:
910 setAlign=LYX_ALIGN_CENTER;
915 if (hasCellSelection()) {
916 if (sel_cell_start > sel_cell_end) {
917 sel_start = sel_cell_end;
918 sel_end = sel_cell_start;
920 sel_start = sel_cell_start;
921 sel_end = sel_cell_end;
924 sel_start = sel_end = actcell;
926 case LyXTabular::SET_PWIDTH:
928 bool update = (tabular->GetPWidth(actcell) != val);
929 tabular->SetPWidth(actcell,val);
931 UpdateLocal(bv, true);
934 case LyXTabular::SET_SPECIAL_COLUMN:
935 case LyXTabular::SET_SPECIAL_MULTI:
936 tabular->SetAlignSpecial(actcell,val,feature);
938 case LyXTabular::APPEND_ROW:
940 // append the row into the tabular
941 tabular->AppendRow(actcell);
942 UpdateLocal(bv, true);
945 case LyXTabular::APPEND_COLUMN:
947 // append the column into the tabular
948 tabular->AppendColumn(actcell);
949 UpdateLocal(bv, true);
952 case LyXTabular::DELETE_ROW:
954 UpdateLocal(bv, true);
956 case LyXTabular::DELETE_COLUMN:
958 /* delete the column from the tabular */
959 tabular->DeleteColumn(actcell);
960 UpdateLocal(bv, true);
963 case LyXTabular::TOGGLE_LINE_TOP:
964 lineSet = !tabular->TopLine(actcell);
965 for(i=sel_start; i<=sel_end; ++i)
966 tabular->SetTopLine(i,lineSet);
967 UpdateLocal(bv, true);
970 case LyXTabular::TOGGLE_LINE_BOTTOM:
971 lineSet = !tabular->BottomLine(actcell);
972 for(i=sel_start; i<=sel_end; ++i)
973 tabular->SetBottomLine(i,lineSet);
974 UpdateLocal(bv, true);
977 case LyXTabular::TOGGLE_LINE_LEFT:
978 lineSet = !tabular->LeftLine(actcell);
979 for(i=sel_start; i<=sel_end; ++i)
980 tabular->SetLeftLine(i,lineSet);
981 UpdateLocal(bv, true);
984 case LyXTabular::TOGGLE_LINE_RIGHT:
985 lineSet = !tabular->RightLine(actcell);
986 for(i=sel_start; i<=sel_end; ++i)
987 tabular->SetRightLine(i,lineSet);
988 UpdateLocal(bv, true);
990 case LyXTabular::ALIGN_LEFT:
991 case LyXTabular::ALIGN_RIGHT:
992 case LyXTabular::ALIGN_CENTER:
993 for(i=sel_start; i<=sel_end; ++i)
994 tabular->SetAlignment(i,setAlign);
995 UpdateLocal(bv, true);
997 case LyXTabular::MULTICOLUMN:
999 if (tabular->row_of_cell(sel_start) !=
1000 tabular->row_of_cell(sel_end)) {
1001 WriteAlert(_("Impossible Operation!"),
1002 _("Multicolumns can only be horizontally."),
1006 // just multicol for one Single Cell
1007 if (!hasCellSelection()) {
1008 // check wether we are completly in a multicol
1009 if (tabular->IsMultiColumn(actcell)) {
1010 tabular->UnsetMultiColumn(actcell);
1011 UpdateLocal(bv, true);
1013 tabular->SetMultiColumn(actcell, 1);
1014 UpdateLocal(bv, false);
1018 // we have a selection so this means we just add all this
1019 // cells to form a multicolumn cell
1023 if (sel_start > sel_end) {
1027 s_start = sel_start;
1030 tabular->SetMultiColumn(s_start, s_end);
1031 cursor.pos = s_start;
1032 sel_cell_end = sel_cell_start;
1033 UpdateLocal(bv, true);
1036 case LyXTabular::SET_ALL_LINES:
1038 case LyXTabular::UNSET_ALL_LINES:
1039 for(i=sel_start; i<=sel_end; ++i)
1040 tabular->SetAllLines(i, setLines);
1041 UpdateLocal(bv, true);
1043 case LyXTabular::SET_LONGTABULAR:
1044 tabular->SetLongTabular(true);
1045 UpdateLocal(bv, true); // because this toggles displayed
1047 case LyXTabular::UNSET_LONGTABULAR:
1048 tabular->SetLongTabular(false);
1049 UpdateLocal(bv, true); // because this toggles displayed
1051 case LyXTabular::SET_ROTATE_TABULAR:
1052 tabular->SetRotateTabular(true);
1054 case LyXTabular::UNSET_ROTATE_TABULAR:
1055 tabular->SetRotateTabular(false);
1057 case LyXTabular::SET_ROTATE_CELL:
1058 for(i=sel_start; i<=sel_end; ++i)
1059 tabular->SetRotateCell(i,true);
1061 case LyXTabular::UNSET_ROTATE_CELL:
1062 for(i=sel_start; i<=sel_end; ++i)
1063 tabular->SetRotateCell(i,false);
1065 case LyXTabular::SET_LINEBREAKS:
1066 what = !tabular->GetLinebreaks(actcell);
1067 for(i=sel_start; i<=sel_end; ++i)
1068 tabular->SetLinebreaks(i,what);
1070 case LyXTabular::SET_LTFIRSTHEAD:
1071 tabular->SetLTHead(actcell,true);
1073 case LyXTabular::SET_LTHEAD:
1074 tabular->SetLTHead(actcell,false);
1076 case LyXTabular::SET_LTFOOT:
1077 tabular->SetLTFoot(actcell,false);
1079 case LyXTabular::SET_LTLASTFOOT:
1080 tabular->SetLTFoot(actcell,true);
1082 case LyXTabular::SET_LTNEWPAGE:
1083 what = !tabular->GetLTNewPage(actcell);
1084 tabular->SetLTNewPage(actcell,what);
1089 void InsetTabular::RemoveTabularRow()
1093 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1096 // the cursor.pos has to be before the inset so if it isn't now just
1097 // reset the curor pos first!
1098 if (cursor.pos % 2) { // behind the inset
1100 resetPos(bv->painter());
1102 UpdatableInset * inset =
1103 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1104 LyXFont font(LyXFont::ALL_SANE);
1106 x = inset->x() + inset->width(bv->painter(), font);
1107 y = inset->descent(bv->painter(), font);
1109 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
1111 inset->Edit(bv, x-inset_x, y-inset_y, button);
1112 if (!the_locking_inset)
1114 UpdateLocal(bv, true);
1118 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1120 InsetText * inset = tabular->GetCellInset(actcell);
1123 if (cursor.pos % 2) { // behind the inset
1124 return (((x+top_x) < cursor.x) &&
1125 ((x+top_x) > (cursor.x - inset->width(bv->painter(),
1126 LyXFont(LyXFont::ALL_SANE)))));
1128 int x2 = cursor.x + tabular->GetBeginningOfTextInCell(actcell);
1129 return ((x1 > x2) &&
1130 (x1 < (x2 + inset->width(bv->painter(),
1131 LyXFont(LyXFont::ALL_SANE)))));
1135 // This returns paperWidth() if the cell-width is unlimited or the width
1136 // in pixels if we have a pwidth for this cell.
1137 int InsetTabular::GetMaxWidthOfCell(Painter & pain, int cell) const
1141 if ((w=tabular->GetPWidth(cell)).empty())
1142 return pain.paperWidth();
1143 return VSpace(w).inPixels( 0, 0);
1146 int InsetTabular::getMaxWidth(Painter & pain,
1147 UpdatableInset const * inset) const
1150 int n = tabular->GetNumberOfCells();
1151 for(cell=0; cell < n; ++cell) {
1152 if (tabular->GetCellInset(cell) == inset)
1156 return pain.paperWidth();
1157 int w = GetMaxWidthOfCell(pain, cell);
1158 // this because text insets remove the xpos from the maxwidth because
1159 // otherwise the would not break good!!!
1160 // w += getCellXPos(cell) + tabular->GetBeginningOfTextInCell(cell);
1165 void InsetTabular::recomputeTextInsets(Painter & pain, const LyXFont & font) const
1171 for(int j= 0; j < tabular->columns(); ++j) {
1172 for(int i = 0; i < tabular->rows(); ++i) {
1173 if (tabular->IsPartOfMultiColumn(i,j))
1175 cell = tabular->GetCellNumber(i,j);
1176 inset = tabular->GetCellInset(cell);
1177 inset->computeTextRows(pain);
1178 tabular->SetWidthOfCell(cell, inset->width(pain, font));
1180 cell = tabular->GetCellNumber(0, j);
1181 cx += tabular->GetWidthOfColumn(cell);