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 "insets/insettext.h"
32 const int ADD_TO_HEIGHT = 2;
33 const int ADD_TO_TABULAR_WIDTH = 2;
41 InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
47 tabular = new LyXTabular(rows,columns,buf);
48 // for now make it always display as display() inset
50 tabular->SetLongTabular(true);
51 the_locking_inset = 0;
53 cursor_visible = false;
55 actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
61 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
63 tabular = new LyXTabular(*(tab.tabular), buf);
64 the_locking_inset = 0;
66 cursor_visible = false;
68 actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
74 InsetTabular::~InsetTabular()
80 Inset * InsetTabular::Clone() const
82 InsetTabular * t = new InsetTabular(*this, buffer);
87 void InsetTabular::Write(ostream & os) const
89 os << " Tabular" << endl;
94 void InsetTabular::Read(LyXLex & lex)
96 // bool old_format = (lex.GetString() == "\\LyXTable");
101 tabular = new LyXTabular(lex, buffer);
104 token = lex.GetString();
105 while (lex.IsOK() && (token != "\\end_inset")) {
107 token = lex.GetString();
109 if (token != "\\end_inset") {
110 lex.printError("Missing \\end_inset at this point. "
113 tabular->SetLongTabular(true);
118 int InsetTabular::ascent(Painter & pain, LyXFont const & font) const
121 calculate_width_of_cells(pain, font);
124 return tabular->GetAscentOfRow(0);
128 int InsetTabular::descent(Painter & pain, LyXFont const & font) const
131 calculate_width_of_cells(pain, font);
134 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0);
138 int InsetTabular::width(Painter & pain, LyXFont const & font) const
141 calculate_width_of_cells(pain, font);
144 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
148 void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline,
155 UpdatableInset::draw(pain,font,baseline,x);
156 if ((top_x != int(x)) || (top_baseline != baseline)) {
158 top_baseline = baseline;
161 for(i=0;i<tabular->rows();++i) {
163 for(j=0;j<tabular->columns();++j) {
164 cx = nx + tabular->GetBeginningOfTextInCell(cell);
165 tabular->GetCellInset(cell)->draw(pain, font, baseline, cx);
166 DrawCellLines(pain, nx, baseline, i, cell);
167 nx += tabular->GetWidthOfColumn(cell);
170 baseline += tabular->GetDescentOfRow(i) + tabular->GetAscentOfRow(i+1)
171 + tabular->GetAdditionalHeight(cell+1);
176 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
177 int row, int cell) const
179 int x2 = x + tabular->GetWidthOfColumn(cell);
182 if (!tabular->TopAlreadyDrawed(cell)) {
183 on_off = !tabular->TopLine(cell);
184 pain.line(x, baseline - tabular->GetAscentOfRow(row),
185 x2, baseline - tabular->GetAscentOfRow(row),
186 on_off ? LColor::tabularonoffline:LColor::tabularline,
187 on_off ? Painter::line_onoffdash:Painter::line_solid);
189 on_off = !tabular->BottomLine(cell);
190 pain.line(x,baseline + tabular->GetDescentOfRow(row),
191 x2, baseline + tabular->GetDescentOfRow(row),
192 on_off ? LColor::tabularonoffline:LColor::tabularline,
193 on_off ? Painter::line_onoffdash:Painter::line_solid);
194 if (!tabular->LeftAlreadyDrawed(cell)) {
195 on_off = !tabular->LeftLine(cell);
196 pain.line(x, baseline - tabular->GetAscentOfRow(row),
197 x, baseline + tabular->GetDescentOfRow(row),
198 on_off ? LColor::tabularonoffline:LColor::tabularline,
199 on_off ? Painter::line_onoffdash:Painter::line_solid);
201 on_off = !tabular->RightLine(cell);
202 pain.line(x2 - tabular->GetAdditionalWidth(cell),
203 baseline - tabular->GetAscentOfRow(row),
204 x2 - tabular->GetAdditionalWidth(cell),
205 baseline + tabular->GetDescentOfRow(row),
206 on_off ? LColor::tabularonoffline:LColor::tabularline,
207 on_off ? Painter::line_onoffdash:Painter::line_solid);
211 char const * InsetTabular::EditMessage() const
213 return _("Opened Tabular Inset");
217 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
219 UpdatableInset::Edit(bv, x, y, button);
221 if (!bv->lockInset(this)) {
222 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
225 the_locking_inset = 0;
226 sel_pos_start = sel_pos_end = inset_pos = inset_x = inset_y = 0;
227 setPos(bv->painter(), x, y);
228 sel_pos_start = sel_pos_end = cursor.pos;
229 bv->text->FinishUndo();
230 if (InsetHit(bv, x, y)) {
231 ActivateCellInset(bv, x, y, button);
233 UpdateLocal(bv, true);
234 // bv->getOwner()->getPopups().updateFormTabular();
238 void InsetTabular::InsetUnlock(BufferView * bv)
240 if (the_locking_inset) {
241 the_locking_inset->InsetUnlock(bv);
242 the_locking_inset = 0;
245 if (hasCharSelection()) {
246 sel_pos_start = sel_pos_end = cursor.pos;
247 UpdateLocal(bv, false);
249 sel_pos_start = sel_pos_end = cursor.pos;
250 no_selection = false;
253 void InsetTabular::UpdateLocal(BufferView * bv, bool flag)
256 calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE));
257 bv->updateInset(this, flag);
260 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
262 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
265 if (inset == tabular->GetCellInset(actcell)) {
266 lyxerr[Debug::INSETS] << "OK" << endl;
267 the_locking_inset = tabular->GetCellInset(actcell);
268 resetPos(bv->painter());
269 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
271 inset_pos = cursor.pos;
273 } else if (the_locking_inset && (the_locking_inset == inset)) {
274 if (cursor.pos == inset_pos) {
275 lyxerr[Debug::INSETS] << "OK" << endl;
276 resetPos(bv->painter());
277 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
280 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
282 } else if (the_locking_inset) {
283 lyxerr[Debug::INSETS] << "MAYBE" << endl;
284 return the_locking_inset->LockInsetInInset(bv, inset);
286 lyxerr[Debug::INSETS] << "NOT OK" << endl;
290 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
293 if (!the_locking_inset)
295 if (the_locking_inset == inset) {
296 the_locking_inset->InsetUnlock(bv);
297 the_locking_inset = 0;
299 moveRight(bv, false);
302 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
305 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
307 if (!the_locking_inset)
309 if (the_locking_inset != inset)
310 return the_locking_inset->UpdateInsetInInset(bv, inset);
316 int InsetTabular::InsetInInsetY()
318 if (!the_locking_inset)
321 return (inset_y + the_locking_inset->InsetInInsetY());
324 void InsetTabular::InsetButtonRelease(BufferView * bv,
325 int x, int y, int button)
327 if (the_locking_inset) {
328 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
331 no_selection = false;
335 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
337 if (hasCharSelection()) {
338 sel_pos_start = sel_pos_end = 0;
339 UpdateLocal(bv, false);
341 no_selection = false;
343 int oldcell = actcell;
345 setPos(bv->painter(), x, y);
347 bool inset_hit = InsetHit(bv, x, y);
349 if ((oldcell == actcell) && the_locking_inset && inset_hit) {
350 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
352 } else if (the_locking_inset) {
353 the_locking_inset->InsetUnlock(bv);
355 the_locking_inset = 0;
356 sel_pos_start = sel_pos_end = cursor.pos;
357 sel_cell_start = sel_cell_end = actcell;
358 if (inset_hit && bv->the_locking_inset) {
359 ActivateCellInset(bv, x, y, button);
360 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
365 bview->getOwner()->getPopups().showFormTabular();
366 else if (oldcell != actcell)
367 bview->getOwner()->getPopups().updateFormTabular();
372 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
374 if (the_locking_inset) {
375 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
376 y - inset_y, button);
380 // int oldcell = actcell,
381 int old = sel_pos_end;
383 setPos(bv->painter(), x, y);
384 sel_pos_end = cursor.pos;
385 sel_cell_end = actcell;
386 if (old != sel_pos_end)
387 UpdateLocal(bv, false);
389 if (oldcell != actcell)
390 bview->getOwner()->getPopups().updateFormTabular();
393 no_selection = false;
397 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
399 if (the_locking_inset) {
400 the_locking_inset->InsetKeyPress(xke);
406 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
409 UpdatableInset::RESULT
412 no_selection = false;
413 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
414 || (result == DISPATCHED_NOUPDATE)) {
416 resetPos(bv->painter());
421 if ((action < 0) && arg.empty())
424 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
425 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
427 if (the_locking_inset) {
428 result=the_locking_inset->LocalDispatch(bv, action, arg);
429 if (result == DISPATCHED_NOUPDATE)
431 else if (result == DISPATCHED) {
432 bool upd = SetCellDimensions(bv->painter(), actcell, actrow);
433 the_locking_inset->ToggleInsetCursor(bv);
434 UpdateLocal(bv, upd);
435 the_locking_inset->ToggleInsetCursor(bv);
437 } else if (result == FINISHED) {
438 if ((action == LFUN_RIGHT) || (action == -1)) {
439 cursor.pos = inset_pos + 1;
440 resetPos(bv->painter());
450 // Normal chars not handled here
453 // --- Cursor Movements ---------------------------------------------
455 moveRight(bv, false);
456 sel_pos_end = cursor.pos;
457 UpdateLocal(bv, false);
460 result = moveRight(bv);
461 if (hasCharSelection()) {
462 sel_pos_start = sel_pos_end = cursor.pos;
463 UpdateLocal(bv, false);
465 sel_pos_start = sel_pos_end = cursor.pos;
469 sel_pos_end = cursor.pos;
470 UpdateLocal(bv, false);
473 result = moveLeft(bv);
474 if (hasCharSelection()) {
475 sel_pos_start = sel_pos_end = cursor.pos;
476 UpdateLocal(bv, false);
478 sel_pos_start = sel_pos_end = cursor.pos;
482 sel_pos_end = cursor.pos;
483 UpdateLocal(bv, false);
487 if (hasCharSelection()) {
488 sel_pos_start = sel_pos_end = cursor.pos;
489 UpdateLocal(bv, false);
491 sel_pos_start = sel_pos_end = cursor.pos;
495 sel_pos_end = cursor.pos;
496 UpdateLocal(bv, false);
500 if (hasCharSelection()) {
501 sel_pos_start = sel_pos_end = cursor.pos;
502 UpdateLocal(bv, false);
504 sel_pos_start = sel_pos_end = cursor.pos;
515 if (hasCharSelection()) {
516 sel_pos_start = sel_pos_end = cursor.pos;
517 UpdateLocal(bv, false);
519 sel_pos_start = sel_pos_end = cursor.pos;
523 result = UNDISPATCHED;
526 if (result!=FINISHED) {
527 if (!the_locking_inset) {
529 if (oldcell != actcell)
530 bview->getOwner()->getPopups().updateFormTabular();
535 bv->unlockInset(this);
540 int InsetTabular::Latex(ostream & os, bool, bool) const
542 return tabular->Latex(os);
546 int InsetTabular::Ascii(ostream &) const
551 int InsetTabular::Linuxdoc(ostream &) const
557 int InsetTabular::DocBook(ostream &) const
563 void InsetTabular::Validate(LaTeXFeatures & features) const
565 if (tabular->IsLongTabular())
566 features.longtable = true;
570 void InsetTabular::calculate_width_of_cells(Painter & pain,
571 LyXFont const & font) const
577 for(int i = 0; i < tabular->rows(); ++i) {
578 maxAsc = maxDesc = 0;
579 for(int j= 0; j < tabular->columns(); ++j) {
580 if (tabular->IsPartOfMultiColumn(i,j))
583 inset = tabular->GetCellInset(cell);
584 maxAsc = max(maxAsc, inset->ascent(pain, font));
585 maxDesc = max(maxDesc, inset->descent(pain, font));
586 tabular->SetWidthOfCell(cell, inset->width(pain, font));
588 tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
589 tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
594 void InsetTabular::GetCursorPos(int & x, int & y) const
601 void InsetTabular::ToggleInsetCursor(BufferView * bv)
603 if (the_locking_inset) {
604 the_locking_inset->ToggleInsetCursor(bv);
608 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
610 int asc = lyxfont::maxAscent(font);
611 int desc = lyxfont::maxDescent(font);
614 bv->hideLockedInsetCursor();
616 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
617 cursor_visible = !cursor_visible;
621 void InsetTabular::ShowInsetCursor(BufferView * bv)
623 if (!cursor_visible) {
624 LyXFont font; // = GetFont(par, cursor.pos);
626 int asc = lyxfont::maxAscent(font);
627 int desc = lyxfont::maxDescent(font);
628 bv->fitLockedInsetCursor(cursor.x, cursor.y, asc, desc);
629 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
630 cursor_visible = true;
635 void InsetTabular::HideInsetCursor(BufferView * bv)
638 ToggleInsetCursor(bv);
642 void InsetTabular::setPos(Painter & pain, int x, int y) const
644 cursor.y = cursor.pos = actcell = actrow = actcol = 0;
645 int ly = tabular->GetDescentOfRow(actrow);
647 // first search the right row
648 while((ly < y) && (actrow < tabular->rows())) {
649 cursor.y += tabular->GetDescentOfRow(actrow) +
650 tabular->GetAscentOfRow(actrow+1) +
651 tabular->GetAdditionalHeight(tabular->GetCellNumber(actcol,actrow+1));
653 ly = cursor.y + tabular->GetDescentOfRow(actrow);
655 actcell = tabular->GetCellNumber(actcol, actrow);
657 // now search the right column
658 int lx = tabular->GetWidthOfColumn(actcell) -
659 tabular->GetAdditionalWidth(actcell);
660 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
661 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
662 tabular->GetAdditionalWidth(actcell-1));
663 cursor.pos = ((actcell+1) * 2) - 1;
665 if ((lx - (tabular->GetWidthOfColumn(actcell)/2)) < x) {
666 cursor.x = lx + top_x - 2;
669 cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
675 void InsetTabular::resetPos(Painter & pain) const
677 actrow = cursor.y = actcol = 0;
680 for(; (cell<actcell) && !tabular->IsLastRow(cell); ++cell) {
681 if (tabular->IsLastCellInRow(cell)) {
682 cursor.y += tabular->GetDescentOfRow(actrow) +
683 tabular->GetAscentOfRow(actrow+1) +
684 tabular->GetAdditionalHeight(cell+1);
688 for(cell=actcell;!tabular->IsFirstCellInRow(cell);--cell)
690 int lx = tabular->GetWidthOfColumn(actcell);
691 for(; (cell < actcell); ++cell) {
692 lx += tabular->GetWidthOfColumn(cell);
695 cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
696 if (cursor.pos % 2) {
697 LyXFont font(LyXFont::ALL_SANE);
698 cursor.x += tabular->GetCellInset(actcell)->width(pain,font) +
699 tabular->GetBeginningOfTextInCell(actcell);
704 bool InsetTabular::SetCellDimensions(Painter & pain, int cell, int row)
706 InsetText * inset = tabular->GetCellInset(cell);
707 LyXFont font(LyXFont::ALL_SANE);
708 int asc = inset->ascent(pain, font) + ADD_TO_HEIGHT;
709 int desc = inset->descent(pain, font) + ADD_TO_HEIGHT;
710 int maxAsc = tabular->GetAscentOfRow(row);
711 int maxDesc = tabular->GetDescentOfRow(row);
712 bool ret = tabular->SetWidthOfCell(cell, inset->width(pain, font));
716 tabular->SetAscentOfRow(row, asc);
718 if (maxDesc < desc) {
720 tabular->SetDescentOfRow(row, desc);
726 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
728 if (cursor.pos % 2) { // behind the inset
730 if (actcell >= tabular->GetNumberOfCells())
734 if (ActivateCellInset(bv))
736 } else { // before the inset
739 resetPos(bv->painter());
740 return DISPATCHED_NOUPDATE;
744 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
749 if (cursor.pos % 2) { // behind the inset
751 } else if (lock) { // behind the inset
752 if (ActivateCellInset(bv, -1, -1))
755 resetPos(bv->painter());
756 return DISPATCHED_NOUPDATE;
760 UpdatableInset::RESULT InsetTabular::moveUp()
762 return DISPATCHED_NOUPDATE;
766 UpdatableInset::RESULT InsetTabular::moveDown()
768 return DISPATCHED_NOUPDATE;
772 bool InsetTabular::moveNextCell()
778 bool InsetTabular::movePrevCell()
784 bool InsetTabular::Delete()
790 void InsetTabular::SetFont(BufferView *, LyXFont const &, bool)
795 void InsetTabular::TabularFeatures(int, string)
803 setAlign = LYX_ALIGN_LEFT,
809 case LyXTabular::ALIGN_LEFT:
810 setAlign=LYX_ALIGN_LEFT;
812 case LyXTabular::ALIGN_RIGHT:
813 setAlign=LYX_ALIGN_RIGHT;
815 case LyXTabular::ALIGN_CENTER:
816 setAlign=LYX_ALIGN_CENTER;
821 if (hasCellSelection()) {
822 if (sel_cell_start > sel_cell_end) {
823 sel_pos_start = sel_cell_end;
824 sel_pos_end = sel_cell_start;
826 sel_pos_start = sel_cell_start;
827 sel_pos_end = sel_cell_end;
830 sel_pos_start = sel_pos_end = actcell;
832 case LyXTabular::SET_PWIDTH:
833 tabular->SetPWidth(actcell,val);
835 case LyXTabular::SET_SPECIAL_COLUMN:
836 case LyXTabular::SET_SPECIAL_MULTI:
837 tabular->SetAlignSpecial(actcell,val,feature);
839 case LyXTabular::APPEND_ROW:
846 // if there is a ContRow following this row I have to add
847 // the row after the ContRow's
848 if ((pos < par->last()) && tabular->RowHasContRow(cell_org)) {
849 while((pos < par->last()) && !tabular->IsContRow(cell)) {
850 while (pos < par->last() && !par->IsNewline(pos))
852 if (pos < par->last())
856 while((pos < par->last()) && tabular->IsContRow(cell)) {
857 while (pos < par->last() && !par->IsNewline(pos))
859 if (pos < par->last())
864 if (pos < par->last())
867 while ((pos < par->last()) &&
868 ((cell == cell_org) || !tabular->IsFirstCell(cell))) {
869 while ((pos < par->last()) && !par->IsNewline(pos))
871 if (pos < par->last())
875 // insert the new cells
876 int number = tabular->NumberOfCellsInRow(cell_org);
877 for (i=0; i<number; ++i)
878 par->InsertChar(pos, LYX_META_NEWLINE);
880 // append the row into the tabular
881 tabular->AppendRow(cell_org);
882 calculate_width_of_cells();
886 case LyXTabular::APPEND_CONT_ROW:
893 // if there is already a controw but not for this cell
894 // the AppendContRow sets only the right values but does
895 // not actually add a row
896 if (tabular->RowHasContRow(cell_org) &&
897 (tabular->CellHasContRow(cell_org) < 0)) {
898 tabular->AppendContRow(cell_org);
899 calculate_width_of_cells();
903 while ((pos < par->last()) &&
904 ((cell == cell_org) || !tabular->IsFirstCell(cell))) {
905 while (pos < par->last() && !par->IsNewline(pos))
907 if (pos < par->last())
911 // insert the new cells
912 int number = tabular->NumberOfCellsInRow(cell_org);
913 for (i=0; i<number; ++i)
914 par->InsertChar(pos, LYX_META_NEWLINE);
915 // append the row into the tabular
916 tabular->AppendContRow(cell_org);
917 calculate_width_of_cells();
921 case LyXTabular::APPEND_COLUMN:
928 if (pos && (par->IsNewline(pos-1))) {
929 if (tabular->AppendCellAfterCell(cell_org, cell)) {
930 par->InsertChar(pos, LYX_META_NEWLINE);
931 if (pos <= cursor.pos)
938 } while (pos <= par->last());
939 // remember that the very last cell doesn't end with a newline.
940 // This saves one byte memory per tabular ;-)
941 if (tabular->AppendCellAfterCell(cell_org, cell))
942 par->InsertChar(par->last(), LYX_META_NEWLINE);
943 // append the column into the tabular
944 tabular->AppendColumn(cell_org);
945 calculate_width_of_cells();
949 case LyXTabular::DELETE_ROW:
951 calculate_width_of_cells();
954 case LyXTabular::DELETE_COLUMN:
959 if (!pos || (par->IsNewline(pos-1))){
960 if (tabular->DeleteCellIfColumnIsDeleted(cell, actcell)) {
962 while (pos < par->last() && !par->IsNewline(pos))
964 if (pos < par->last())
967 par->Erase(pos - 1); // the missing newline
968 // at the end of a tabular
969 --pos; // because of ++pos below
974 } while (pos <= par->last());
975 /* delete the column from the tabular */
976 tabular->DeleteColumn(actcell);
977 calculate_width_of_cells();
981 case LyXTabular::TOGGLE_LINE_TOP:
982 lineSet = !tabular->TopLine(actcell);
983 for(i=sel_pos_start; i<=sel_pos_end; ++i)
984 tabular->SetTopLine(i,lineSet);
985 calculate_width_of_cells();
989 case LyXTabular::TOGGLE_LINE_BOTTOM:
990 lineSet = !tabular->BottomLine(actcell);
991 for(i=sel_pos_start; i<=sel_pos_end; ++i)
992 tabular->SetBottomLine(i,lineSet);
993 calculate_width_of_cells();
997 case LyXTabular::TOGGLE_LINE_LEFT:
998 lineSet = !tabular->LeftLine(actcell);
999 for(i=sel_pos_start; i<=sel_pos_end; ++i)
1000 tabular->SetLeftLine(i,lineSet);
1001 calculate_width_of_cells();
1005 case LyXTabular::TOGGLE_LINE_RIGHT:
1006 lineSet = !tabular->RightLine(actcell);
1007 for(i=sel_pos_start; i<=sel_pos_end; ++i)
1008 tabular->SetRightLine(i,lineSet);
1009 calculate_width_of_cells();
1012 case LyXTabular::ALIGN_LEFT:
1013 case LyXTabular::ALIGN_RIGHT:
1014 case LyXTabular::ALIGN_CENTER:
1015 for(i=sel_pos_start; i<=sel_pos_end; ++i)
1016 tabular->SetAlignment(i,setAlign);
1019 case LyXTabular::MULTICOLUMN:
1021 if (tabular->row_of_cell(sel_pos_start) !=
1022 tabular->row_of_cell(sel_pos_end)) {
1023 WriteAlert(_("Impossible Operation!"),
1024 _("Multicolumns can only be horizontally."),
1028 // just multicol for one Single Cell
1029 if (!hasCellSelection()) {
1030 // check wether we are completly in a multicol
1031 if (tabular->IsMultiColumn(actcell)) {
1035 if ((newlines=tabular->UnsetMultiColumn(actcell))) {
1036 while ((pos < par->last()) && !par->IsNewline(pos))
1038 for (;newlines;--newlines)
1039 par->InsertChar(pos, LYX_META_NEWLINE);
1041 calculate_width_of_cells();
1043 tabular->SetMultiColumn(actcell, 1);
1048 // we have a selection so this means we just add all this
1049 // cells to form a multicolumn cell
1054 if (sel_pos_start > sel_pos_end) {
1055 s_start = sel_pos_end;
1056 s_end = sel_pos_start;
1058 s_start = sel_pos_start;
1059 s_end = sel_pos_end;
1061 for(i=s_start; i < s_end; ++i) {
1062 if (par->IsNewline(i)) {
1064 // check for double-blanks
1065 if ((i && !par->IsLineSeparator(i-1)) &&
1066 (i < par->last()) && !par->IsLineSeparator(i))
1067 par->InsertChar(i, ' ');
1073 tabular->SetMultiColumn(sel_pos_start,number);
1074 cursor.pos = s_start;
1075 sel_cell_end = sel_cell_start;
1076 calculate_width_of_cells();
1080 case LyXTabular::SET_ALL_LINES:
1082 case LyXTabular::UNSET_ALL_LINES:
1083 for(i=sel_pos_start; i<=sel_pos_end; ++i)
1084 tabular->SetAllLines(i, setLines);
1085 calculate_width_of_cells();
1088 case LyXTabular::SET_LONGTABULAR:
1089 tabular->SetLongTabular(true);
1090 UpdateLocal(); // because this toggles displayed
1092 case LyXTabular::UNSET_LONGTABULAR:
1093 tabular->SetLongTabular(false);
1094 UpdateLocal(); // because this toggles displayed
1096 case LyXTabular::SET_ROTATE_TABULAR:
1097 tabular->SetRotateTabular(true);
1099 case LyXTabular::UNSET_ROTATE_TABULAR:
1100 tabular->SetRotateTabular(false);
1102 case LyXTabular::SET_ROTATE_CELL:
1103 for(i=sel_pos_start; i<=sel_pos_end; ++i)
1104 tabular->SetRotateCell(i,true);
1106 case LyXTabular::UNSET_ROTATE_CELL:
1107 for(i=sel_pos_start; i<=sel_pos_end; ++i)
1108 tabular->SetRotateCell(i,false);
1110 case LyXTabular::SET_LINEBREAKS:
1111 what = !tabular->Linebreaks(tabular->FirstVirtualCell(actcell));
1112 for(i=sel_pos_start; i<=sel_pos_end; ++i)
1113 tabular->SetLinebreaks(i,what);
1115 case LyXTabular::SET_LTFIRSTHEAD:
1116 tabular->SetLTHead(actcell,true);
1118 case LyXTabular::SET_LTHEAD:
1119 tabular->SetLTHead(actcell,false);
1121 case LyXTabular::SET_LTFOOT:
1122 tabular->SetLTFoot(actcell,false);
1124 case LyXTabular::SET_LTLASTFOOT:
1125 tabular->SetLTFoot(actcell,true);
1127 case LyXTabular::SET_LTNEWPAGE:
1128 what = !tabular->LTNewPage(actcell);
1129 tabular->SetLTNewPage(actcell,what);
1135 void InsetTabular::RemoveTabularRow()
1139 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button)
1141 // the cursor.pos has to be before the inset so if it isn't now just
1142 // reset the curor pos first!
1143 if (cursor.pos % 2) { // behind the inset
1145 resetPos(bv->painter());
1147 UpdatableInset * inset =
1148 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1149 LyXFont font(LyXFont::ALL_SANE);
1151 x = inset->width(bv->painter(), font) + top_x;
1153 y = inset->descent(bv->painter(), font);
1154 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
1156 inset->Edit(bv, x-inset_x, y-inset_y, button);
1157 if (!the_locking_inset)
1159 UpdateLocal(bv, true);
1163 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1165 InsetText * inset = tabular->GetCellInset(actcell);
1168 if (cursor.pos % 2) { // behind the inset
1169 return (((x+top_x) < cursor.x) &&
1170 ((x+top_x) > (cursor.x - inset->width(bv->painter(),
1171 LyXFont(LyXFont::ALL_SANE)))));
1173 int x2 = cursor.x + tabular->GetBeginningOfTextInCell(actcell);
1174 return ((x1 > x2) &&
1175 (x1 < (x2 + inset->width(bv->painter(),
1176 LyXFont(LyXFont::ALL_SANE)))));