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 bool MenuLayoutTable(int);
37 const int ADD_TO_HEIGHT = 2;
38 const int ADD_TO_TABULAR_WIDTH = 2;
46 InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
52 tabular = new LyXTabular(rows,columns,buf);
53 // for now make it always display as display() inset
55 tabular->SetLongTabular(true);
56 the_locking_inset = 0;
58 cursor_visible = false;
60 actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
66 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
68 tabular = new LyXTabular(*(tab.tabular), buf);
69 the_locking_inset = 0;
71 cursor_visible = false;
73 actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
79 InsetTabular::~InsetTabular()
85 Inset * InsetTabular::Clone() const
87 InsetTabular * t = new InsetTabular(*this, buffer);
92 void InsetTabular::Write(ostream & os) const
94 os << " Tabular" << endl;
99 void InsetTabular::Read(LyXLex & lex)
101 // bool old_format = (lex.GetString() == "\\LyXTable");
106 tabular = new LyXTabular(lex, buffer);
109 token = lex.GetString();
110 while (lex.IsOK() && (token != "\\end_inset")) {
112 token = lex.GetString();
114 if (token != "\\end_inset") {
115 lex.printError("Missing \\end_inset at this point. "
118 tabular->SetLongTabular(true);
123 int InsetTabular::ascent(Painter & pain, LyXFont const & font) const
126 calculate_width_of_cells(pain, font);
129 return tabular->GetAscentOfRow(0);
133 int InsetTabular::descent(Painter & pain, LyXFont const & font) const
136 calculate_width_of_cells(pain, font);
139 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0);
143 int InsetTabular::width(Painter & pain, LyXFont const & font) const
146 calculate_width_of_cells(pain, font);
149 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
153 void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline,
160 UpdatableInset::draw(pain,font,baseline,x);
161 if ((top_x != int(x)) || (top_baseline != baseline)) {
163 top_baseline = baseline;
166 for(i=0;i<tabular->rows();++i) {
168 for(j=0;j<tabular->columns();++j) {
169 cx = nx + tabular->GetBeginningOfTextInCell(cell);
170 tabular->GetCellInset(cell)->draw(pain, font, baseline, cx);
171 DrawCellLines(pain, nx, baseline, i, cell);
172 nx += tabular->GetWidthOfColumn(cell);
175 baseline += tabular->GetDescentOfRow(i) + tabular->GetAscentOfRow(i+1)
176 + tabular->GetAdditionalHeight(cell+1);
181 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
182 int row, int cell) const
184 int x2 = x + tabular->GetWidthOfColumn(cell);
187 if (!tabular->TopAlreadyDrawed(cell)) {
188 on_off = !tabular->TopLine(cell);
189 pain.line(x, baseline - tabular->GetAscentOfRow(row),
190 x2, baseline - tabular->GetAscentOfRow(row),
191 on_off ? LColor::tabularonoffline:LColor::tabularline,
192 on_off ? Painter::line_onoffdash:Painter::line_solid);
194 on_off = !tabular->BottomLine(cell);
195 pain.line(x,baseline + tabular->GetDescentOfRow(row),
196 x2, baseline + tabular->GetDescentOfRow(row),
197 on_off ? LColor::tabularonoffline:LColor::tabularline,
198 on_off ? Painter::line_onoffdash:Painter::line_solid);
199 if (!tabular->LeftAlreadyDrawed(cell)) {
200 on_off = !tabular->LeftLine(cell);
201 pain.line(x, baseline - tabular->GetAscentOfRow(row),
202 x, baseline + tabular->GetDescentOfRow(row),
203 on_off ? LColor::tabularonoffline:LColor::tabularline,
204 on_off ? Painter::line_onoffdash:Painter::line_solid);
206 on_off = !tabular->RightLine(cell);
207 pain.line(x2 - tabular->GetAdditionalWidth(cell),
208 baseline - tabular->GetAscentOfRow(row),
209 x2 - tabular->GetAdditionalWidth(cell),
210 baseline + tabular->GetDescentOfRow(row),
211 on_off ? LColor::tabularonoffline:LColor::tabularline,
212 on_off ? Painter::line_onoffdash:Painter::line_solid);
216 char const * InsetTabular::EditMessage() const
218 return _("Opened Tabular Inset");
222 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
224 UpdatableInset::Edit(bv, x, y, button);
226 if (!bv->lockInset(this)) {
227 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
230 the_locking_inset = 0;
231 sel_pos_start = sel_pos_end = inset_pos = inset_x = inset_y = 0;
232 setPos(bv->painter(), x, y);
233 sel_pos_start = sel_pos_end = cursor.pos;
234 bv->text->FinishUndo();
235 if (InsetHit(bv, x, y)) {
236 ActivateCellInset(bv, x, y, button);
238 UpdateLocal(bv, true);
239 // bv->getOwner()->getPopups().updateFormTabular();
243 void InsetTabular::InsetUnlock(BufferView * bv)
245 if (the_locking_inset) {
246 the_locking_inset->InsetUnlock(bv);
247 the_locking_inset = 0;
250 if (hasCharSelection()) {
251 sel_pos_start = sel_pos_end = cursor.pos;
252 UpdateLocal(bv, false);
254 sel_pos_start = sel_pos_end = cursor.pos;
255 no_selection = false;
258 void InsetTabular::UpdateLocal(BufferView * bv, bool flag)
261 calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE));
262 resetPos(bv->painter());
264 bv->updateInset(this, flag);
267 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
269 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
272 if (inset == tabular->GetCellInset(actcell)) {
273 lyxerr[Debug::INSETS] << "OK" << endl;
274 the_locking_inset = tabular->GetCellInset(actcell);
275 resetPos(bv->painter());
276 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
278 inset_pos = cursor.pos;
280 } else if (the_locking_inset && (the_locking_inset == inset)) {
281 if (cursor.pos == inset_pos) {
282 lyxerr[Debug::INSETS] << "OK" << endl;
283 resetPos(bv->painter());
284 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
287 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
289 } else if (the_locking_inset) {
290 lyxerr[Debug::INSETS] << "MAYBE" << endl;
291 return the_locking_inset->LockInsetInInset(bv, inset);
293 lyxerr[Debug::INSETS] << "NOT OK" << endl;
297 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
300 if (!the_locking_inset)
302 if (the_locking_inset == inset) {
303 the_locking_inset->InsetUnlock(bv);
304 the_locking_inset = 0;
306 moveRight(bv, false);
309 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
312 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
314 if (!the_locking_inset)
316 if (the_locking_inset != inset)
317 return the_locking_inset->UpdateInsetInInset(bv, inset);
323 int InsetTabular::InsetInInsetY()
325 if (!the_locking_inset)
328 return (inset_y + the_locking_inset->InsetInInsetY());
331 void InsetTabular::InsetButtonRelease(BufferView * bv,
332 int x, int y, int button)
335 LocalDispatch(bv, LFUN_LAYOUT_TABLE, "true");
338 if (the_locking_inset) {
339 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
342 no_selection = false;
346 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
348 if (hasCharSelection()) {
349 sel_pos_start = sel_pos_end = 0;
350 UpdateLocal(bv, false);
352 no_selection = false;
354 int oldcell = actcell;
356 setPos(bv->painter(), x, y);
358 bool inset_hit = InsetHit(bv, x, y);
360 if ((oldcell == actcell) && the_locking_inset && inset_hit) {
361 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
363 } else if (the_locking_inset) {
364 the_locking_inset->InsetUnlock(bv);
366 the_locking_inset = 0;
367 sel_pos_start = sel_pos_end = cursor.pos;
368 sel_cell_start = sel_cell_end = actcell;
369 if (inset_hit && bv->the_locking_inset) {
370 ActivateCellInset(bv, x, y, button);
371 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
376 bview->getOwner()->getPopups().showFormTabular();
377 else if (oldcell != actcell)
378 bview->getOwner()->getPopups().updateFormTabular();
383 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
385 if (the_locking_inset) {
386 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
387 y - inset_y, button);
391 // int oldcell = actcell,
392 int old = sel_pos_end;
394 setPos(bv->painter(), x, y);
395 sel_pos_end = cursor.pos;
396 sel_cell_end = actcell;
397 if (old != sel_pos_end)
398 UpdateLocal(bv, false);
400 if (oldcell != actcell)
401 bview->getOwner()->getPopups().updateFormTabular();
404 no_selection = false;
408 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
410 if (the_locking_inset) {
411 the_locking_inset->InsetKeyPress(xke);
417 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
420 UpdatableInset::RESULT
423 no_selection = false;
424 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
425 || (result == DISPATCHED_NOUPDATE)) {
427 resetPos(bv->painter());
432 if ((action < 0) && arg.empty())
435 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
436 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
438 if (the_locking_inset) {
439 result=the_locking_inset->LocalDispatch(bv, action, arg);
440 if (result == DISPATCHED_NOUPDATE)
442 else if (result == DISPATCHED) {
443 bool upd = SetCellDimensions(bv->painter(), actcell, actrow);
444 the_locking_inset->ToggleInsetCursor(bv);
445 UpdateLocal(bv, upd);
446 the_locking_inset->ToggleInsetCursor(bv);
448 } else if (result == FINISHED) {
449 if ((action == LFUN_RIGHT) || (action == -1)) {
450 cursor.pos = inset_pos + 1;
451 resetPos(bv->painter());
461 // Normal chars not handled here
464 // --- Cursor Movements ---------------------------------------------
466 moveRight(bv, false);
467 sel_pos_end = cursor.pos;
468 UpdateLocal(bv, false);
471 result = moveRight(bv);
472 if (hasCharSelection()) {
473 sel_pos_start = sel_pos_end = cursor.pos;
474 UpdateLocal(bv, false);
476 sel_pos_start = sel_pos_end = cursor.pos;
480 sel_pos_end = cursor.pos;
481 UpdateLocal(bv, false);
484 result = moveLeft(bv);
485 if (hasCharSelection()) {
486 sel_pos_start = sel_pos_end = cursor.pos;
487 UpdateLocal(bv, false);
489 sel_pos_start = sel_pos_end = cursor.pos;
493 sel_pos_end = cursor.pos;
494 UpdateLocal(bv, false);
498 if (hasCharSelection()) {
499 sel_pos_start = sel_pos_end = cursor.pos;
500 UpdateLocal(bv, false);
502 sel_pos_start = sel_pos_end = cursor.pos;
506 sel_pos_end = cursor.pos;
507 UpdateLocal(bv, false);
511 if (hasCharSelection()) {
512 sel_pos_start = sel_pos_end = cursor.pos;
513 UpdateLocal(bv, false);
515 sel_pos_start = sel_pos_end = cursor.pos;
526 if (hasCharSelection()) {
527 sel_pos_start = sel_pos_end = cursor.pos;
528 UpdateLocal(bv, false);
530 sel_pos_start = sel_pos_end = cursor.pos;
533 case LFUN_LAYOUT_TABLE:
535 int flag = (arg == "true");
536 MenuLayoutTable(flag);
540 result = UNDISPATCHED;
543 if (result!=FINISHED) {
544 if (!the_locking_inset) {
546 if (oldcell != actcell)
547 bview->getOwner()->getPopups().updateFormTabular();
552 bv->unlockInset(this);
557 int InsetTabular::Latex(ostream & os, bool, bool) const
559 return tabular->Latex(os);
563 int InsetTabular::Ascii(ostream &) const
568 int InsetTabular::Linuxdoc(ostream &) const
574 int InsetTabular::DocBook(ostream &) const
580 void InsetTabular::Validate(LaTeXFeatures & features) const
582 if (tabular->IsLongTabular())
583 features.longtable = true;
587 void InsetTabular::calculate_width_of_cells(Painter & pain,
588 LyXFont const & font) const
594 for(int i = 0; i < tabular->rows(); ++i) {
595 maxAsc = maxDesc = 0;
596 for(int j= 0; j < tabular->columns(); ++j) {
597 if (tabular->IsPartOfMultiColumn(i,j))
600 inset = tabular->GetCellInset(cell);
601 maxAsc = max(maxAsc, inset->ascent(pain, font));
602 maxDesc = max(maxDesc, inset->descent(pain, font));
603 tabular->SetWidthOfCell(cell, inset->width(pain, font));
605 tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
606 tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
611 void InsetTabular::GetCursorPos(int & x, int & y) const
618 void InsetTabular::ToggleInsetCursor(BufferView * bv)
620 if (the_locking_inset) {
621 the_locking_inset->ToggleInsetCursor(bv);
625 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
627 int asc = lyxfont::maxAscent(font);
628 int desc = lyxfont::maxDescent(font);
631 bv->hideLockedInsetCursor();
633 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
634 cursor_visible = !cursor_visible;
638 void InsetTabular::ShowInsetCursor(BufferView * bv)
640 if (!cursor_visible) {
641 LyXFont font; // = GetFont(par, cursor.pos);
643 int asc = lyxfont::maxAscent(font);
644 int desc = lyxfont::maxDescent(font);
645 bv->fitLockedInsetCursor(cursor.x, cursor.y, asc, desc);
646 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
647 cursor_visible = true;
652 void InsetTabular::HideInsetCursor(BufferView * bv)
655 ToggleInsetCursor(bv);
659 void InsetTabular::setPos(Painter & pain, int x, int y) const
661 cursor.y = cursor.pos = actcell = actrow = actcol = 0;
662 int ly = tabular->GetDescentOfRow(actrow);
664 // first search the right row
665 while((ly < y) && (actrow < tabular->rows())) {
666 cursor.y += tabular->GetDescentOfRow(actrow) +
667 tabular->GetAscentOfRow(actrow+1) +
668 tabular->GetAdditionalHeight(tabular->GetCellNumber(actcol,actrow+1));
670 ly = cursor.y + tabular->GetDescentOfRow(actrow);
672 actcell = tabular->GetCellNumber(actcol, actrow);
674 // now search the right column
675 int lx = tabular->GetWidthOfColumn(actcell) -
676 tabular->GetAdditionalWidth(actcell);
677 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
678 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
679 tabular->GetAdditionalWidth(actcell-1));
680 cursor.pos = ((actcell+1) * 2) - 1;
682 if ((lx - (tabular->GetWidthOfColumn(actcell)/2)) < x) {
683 cursor.x = lx + top_x - 2;
686 cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
692 void InsetTabular::resetPos(Painter & pain) const
694 actrow = cursor.y = actcol = 0;
697 for(; (cell<actcell) && !tabular->IsLastRow(cell); ++cell) {
698 if (tabular->IsLastCellInRow(cell)) {
699 cursor.y += tabular->GetDescentOfRow(actrow) +
700 tabular->GetAscentOfRow(actrow+1) +
701 tabular->GetAdditionalHeight(cell+1);
705 for(cell=actcell;!tabular->IsFirstCellInRow(cell);--cell)
707 int lx = tabular->GetWidthOfColumn(actcell);
708 for(; (cell < actcell); ++cell) {
709 lx += tabular->GetWidthOfColumn(cell);
712 cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
713 if (cursor.pos % 2) {
714 LyXFont font(LyXFont::ALL_SANE);
715 cursor.x += tabular->GetCellInset(actcell)->width(pain,font) +
716 tabular->GetBeginningOfTextInCell(actcell);
721 bool InsetTabular::SetCellDimensions(Painter & pain, int cell, int row)
723 InsetText * inset = tabular->GetCellInset(cell);
724 LyXFont font(LyXFont::ALL_SANE);
725 int asc = inset->ascent(pain, font) + ADD_TO_HEIGHT;
726 int desc = inset->descent(pain, font) + ADD_TO_HEIGHT;
727 int maxAsc = tabular->GetAscentOfRow(row);
728 int maxDesc = tabular->GetDescentOfRow(row);
729 bool ret = tabular->SetWidthOfCell(cell, inset->width(pain, font));
733 tabular->SetAscentOfRow(row, asc);
735 if (maxDesc < desc) {
737 tabular->SetDescentOfRow(row, desc);
743 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
745 if (cursor.pos % 2) { // behind the inset
747 if (actcell >= tabular->GetNumberOfCells())
751 if (ActivateCellInset(bv))
753 } else { // before the inset
756 resetPos(bv->painter());
757 return DISPATCHED_NOUPDATE;
761 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
766 if (cursor.pos % 2) { // behind the inset
768 } else if (lock) { // behind the inset
769 if (ActivateCellInset(bv, -1, -1))
772 resetPos(bv->painter());
773 return DISPATCHED_NOUPDATE;
777 UpdatableInset::RESULT InsetTabular::moveUp()
779 return DISPATCHED_NOUPDATE;
783 UpdatableInset::RESULT InsetTabular::moveDown()
785 return DISPATCHED_NOUPDATE;
789 bool InsetTabular::moveNextCell()
795 bool InsetTabular::movePrevCell()
801 bool InsetTabular::Delete()
807 void InsetTabular::SetFont(BufferView *, LyXFont const &, bool)
812 void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val)
819 setAlign = LYX_ALIGN_LEFT,
825 case LyXTabular::ALIGN_LEFT:
826 setAlign=LYX_ALIGN_LEFT;
828 case LyXTabular::ALIGN_RIGHT:
829 setAlign=LYX_ALIGN_RIGHT;
831 case LyXTabular::ALIGN_CENTER:
832 setAlign=LYX_ALIGN_CENTER;
837 if (hasCellSelection()) {
838 if (sel_cell_start > sel_cell_end) {
839 sel_pos_start = sel_cell_end;
840 sel_pos_end = sel_cell_start;
842 sel_pos_start = sel_cell_start;
843 sel_pos_end = sel_cell_end;
846 sel_pos_start = sel_pos_end = actcell;
848 case LyXTabular::SET_PWIDTH:
849 tabular->SetPWidth(actcell,val);
851 case LyXTabular::SET_SPECIAL_COLUMN:
852 case LyXTabular::SET_SPECIAL_MULTI:
853 tabular->SetAlignSpecial(actcell,val,feature);
855 case LyXTabular::APPEND_ROW:
857 // append the row into the tabular
858 tabular->AppendRow(actcell);
859 UpdateLocal(bv, true);
862 case LyXTabular::APPEND_COLUMN:
864 // append the column into the tabular
865 tabular->AppendColumn(actcell);
866 UpdateLocal(bv, true);
869 case LyXTabular::DELETE_ROW:
871 UpdateLocal(bv, true);
873 case LyXTabular::DELETE_COLUMN:
875 /* delete the column from the tabular */
876 tabular->DeleteColumn(actcell);
877 UpdateLocal(bv, true);
880 case LyXTabular::TOGGLE_LINE_TOP:
881 lineSet = !tabular->TopLine(actcell);
882 for(i=sel_pos_start; i<=sel_pos_end; ++i)
883 tabular->SetTopLine(i,lineSet);
884 UpdateLocal(bv, true);
887 case LyXTabular::TOGGLE_LINE_BOTTOM:
888 lineSet = !tabular->BottomLine(actcell);
889 for(i=sel_pos_start; i<=sel_pos_end; ++i)
890 tabular->SetBottomLine(i,lineSet);
891 UpdateLocal(bv, true);
894 case LyXTabular::TOGGLE_LINE_LEFT:
895 lineSet = !tabular->LeftLine(actcell);
896 for(i=sel_pos_start; i<=sel_pos_end; ++i)
897 tabular->SetLeftLine(i,lineSet);
898 UpdateLocal(bv, true);
901 case LyXTabular::TOGGLE_LINE_RIGHT:
902 lineSet = !tabular->RightLine(actcell);
903 for(i=sel_pos_start; i<=sel_pos_end; ++i)
904 tabular->SetRightLine(i,lineSet);
905 UpdateLocal(bv, true);
907 case LyXTabular::ALIGN_LEFT:
908 case LyXTabular::ALIGN_RIGHT:
909 case LyXTabular::ALIGN_CENTER:
910 for(i=sel_pos_start; i<=sel_pos_end; ++i)
911 tabular->SetAlignment(i,setAlign);
912 UpdateLocal(bv, true);
914 case LyXTabular::MULTICOLUMN:
916 if (tabular->row_of_cell(sel_pos_start) !=
917 tabular->row_of_cell(sel_pos_end)) {
918 WriteAlert(_("Impossible Operation!"),
919 _("Multicolumns can only be horizontally."),
923 // just multicol for one Single Cell
924 if (!hasCellSelection()) {
925 // check wether we are completly in a multicol
926 if (tabular->IsMultiColumn(actcell)) {
927 tabular->UnsetMultiColumn(actcell);
928 UpdateLocal(bv, true);
930 tabular->SetMultiColumn(actcell, 1);
931 UpdateLocal(bv, false);
935 // we have a selection so this means we just add all this
936 // cells to form a multicolumn cell
940 if (sel_pos_start > sel_pos_end) {
941 s_start = sel_pos_end;
942 s_end = sel_pos_start;
944 s_start = sel_pos_start;
947 tabular->SetMultiColumn(s_start, s_end);
948 cursor.pos = s_start;
949 sel_cell_end = sel_cell_start;
950 UpdateLocal(bv, true);
953 case LyXTabular::SET_ALL_LINES:
955 case LyXTabular::UNSET_ALL_LINES:
956 for(i=sel_pos_start; i<=sel_pos_end; ++i)
957 tabular->SetAllLines(i, setLines);
958 UpdateLocal(bv, true);
960 case LyXTabular::SET_LONGTABULAR:
961 tabular->SetLongTabular(true);
962 UpdateLocal(bv, true); // because this toggles displayed
964 case LyXTabular::UNSET_LONGTABULAR:
965 tabular->SetLongTabular(false);
966 UpdateLocal(bv, true); // because this toggles displayed
968 case LyXTabular::SET_ROTATE_TABULAR:
969 tabular->SetRotateTabular(true);
971 case LyXTabular::UNSET_ROTATE_TABULAR:
972 tabular->SetRotateTabular(false);
974 case LyXTabular::SET_ROTATE_CELL:
975 for(i=sel_pos_start; i<=sel_pos_end; ++i)
976 tabular->SetRotateCell(i,true);
978 case LyXTabular::UNSET_ROTATE_CELL:
979 for(i=sel_pos_start; i<=sel_pos_end; ++i)
980 tabular->SetRotateCell(i,false);
982 case LyXTabular::SET_LINEBREAKS:
983 what = !tabular->GetLinebreaks(actcell);
984 for(i=sel_pos_start; i<=sel_pos_end; ++i)
985 tabular->SetLinebreaks(i,what);
987 case LyXTabular::SET_LTFIRSTHEAD:
988 tabular->SetLTHead(actcell,true);
990 case LyXTabular::SET_LTHEAD:
991 tabular->SetLTHead(actcell,false);
993 case LyXTabular::SET_LTFOOT:
994 tabular->SetLTFoot(actcell,false);
996 case LyXTabular::SET_LTLASTFOOT:
997 tabular->SetLTFoot(actcell,true);
999 case LyXTabular::SET_LTNEWPAGE:
1000 what = !tabular->GetLTNewPage(actcell);
1001 tabular->SetLTNewPage(actcell,what);
1006 void InsetTabular::RemoveTabularRow()
1010 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button)
1012 // the cursor.pos has to be before the inset so if it isn't now just
1013 // reset the curor pos first!
1014 if (cursor.pos % 2) { // behind the inset
1016 resetPos(bv->painter());
1018 UpdatableInset * inset =
1019 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1020 LyXFont font(LyXFont::ALL_SANE);
1022 x = inset->width(bv->painter(), font) + top_x;
1024 y = inset->descent(bv->painter(), font);
1025 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
1027 inset->Edit(bv, x-inset_x, y-inset_y, button);
1028 if (!the_locking_inset)
1030 UpdateLocal(bv, true);
1034 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1036 InsetText * inset = tabular->GetCellInset(actcell);
1039 if (cursor.pos % 2) { // behind the inset
1040 return (((x+top_x) < cursor.x) &&
1041 ((x+top_x) > (cursor.x - inset->width(bv->painter(),
1042 LyXFont(LyXFont::ALL_SANE)))));
1044 int x2 = cursor.x + tabular->GetBeginningOfTextInCell(actcell);
1045 return ((x1 > x2) &&
1046 (x1 < (x2 + inset->width(bv->painter(),
1047 LyXFont(LyXFont::ALL_SANE)))));