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"
31 #include "insets/insettext.h"
33 const int ADD_TO_HEIGHT = 2;
34 const int ADD_TO_TABULAR_WIDTH = 2;
42 InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
48 tabular = new LyXTabular(rows,columns,buf);
49 // for now make it always display as display() inset
51 tabular->SetLongTabular(true);
52 the_locking_inset = 0;
54 cursor_visible = false;
56 actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
62 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
64 tabular = new LyXTabular(*(tab.tabular), buf);
65 the_locking_inset = 0;
67 cursor_visible = false;
69 actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
75 InsetTabular::~InsetTabular()
81 Inset * InsetTabular::Clone() const
83 InsetTabular * t = new InsetTabular(*this, buffer);
88 void InsetTabular::Write(ostream & os) const
90 os << " Tabular" << endl;
95 void InsetTabular::Read(LyXLex & lex)
97 // bool old_format = (lex.GetString() == "\\LyXTable");
102 tabular = new LyXTabular(lex, buffer);
105 token = lex.GetString();
106 while (lex.IsOK() && (token != "\\end_inset")) {
108 token = lex.GetString();
110 if (token != "\\end_inset") {
111 lex.printError("Missing \\end_inset at this point. "
114 tabular->SetLongTabular(true);
119 int InsetTabular::ascent(Painter & pain, LyXFont const & font) const
122 calculate_width_of_cells(pain, font);
125 return tabular->GetAscentOfRow(0);
129 int InsetTabular::descent(Painter & pain, LyXFont const & font) const
132 calculate_width_of_cells(pain, font);
135 return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0);
139 int InsetTabular::width(Painter & pain, LyXFont const & font) const
142 calculate_width_of_cells(pain, font);
145 return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
149 void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline,
156 UpdatableInset::draw(pain,font,baseline,x);
157 if ((top_x != int(x)) || (top_baseline != baseline)) {
159 top_baseline = baseline;
162 for(i=0;i<tabular->rows();++i) {
164 for(j=0;j<tabular->columns();++j) {
165 cx = nx + tabular->GetBeginningOfTextInCell(cell);
166 tabular->GetCellInset(cell)->draw(pain, font, baseline, cx);
167 DrawCellLines(pain, nx, baseline, i, cell);
168 nx += tabular->GetWidthOfColumn(cell);
171 baseline += tabular->GetDescentOfRow(i) + tabular->GetAscentOfRow(i+1)
172 + tabular->GetAdditionalHeight(cell+1);
177 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
178 int row, int cell) const
180 int x2 = x + tabular->GetWidthOfColumn(cell);
183 if (!tabular->TopAlreadyDrawed(cell)) {
184 on_off = !tabular->TopLine(cell);
185 pain.line(x, baseline - tabular->GetAscentOfRow(row),
186 x2, baseline - tabular->GetAscentOfRow(row),
187 on_off ? LColor::tabularonoffline:LColor::tabularline,
188 on_off ? Painter::line_onoffdash:Painter::line_solid);
190 on_off = !tabular->BottomLine(cell);
191 pain.line(x,baseline + tabular->GetDescentOfRow(row),
192 x2, baseline + tabular->GetDescentOfRow(row),
193 on_off ? LColor::tabularonoffline:LColor::tabularline,
194 on_off ? Painter::line_onoffdash:Painter::line_solid);
195 if (!tabular->LeftAlreadyDrawed(cell)) {
196 on_off = !tabular->LeftLine(cell);
197 pain.line(x, baseline - tabular->GetAscentOfRow(row),
198 x, baseline + tabular->GetDescentOfRow(row),
199 on_off ? LColor::tabularonoffline:LColor::tabularline,
200 on_off ? Painter::line_onoffdash:Painter::line_solid);
202 on_off = !tabular->RightLine(cell);
203 pain.line(x2 - tabular->GetAdditionalWidth(cell),
204 baseline - tabular->GetAscentOfRow(row),
205 x2 - tabular->GetAdditionalWidth(cell),
206 baseline + tabular->GetDescentOfRow(row),
207 on_off ? LColor::tabularonoffline:LColor::tabularline,
208 on_off ? Painter::line_onoffdash:Painter::line_solid);
212 char const * InsetTabular::EditMessage() const
214 return _("Opened Tabular Inset");
218 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
220 UpdatableInset::Edit(bv, x, y, button);
222 if (!bv->lockInset(this)) {
223 lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
226 the_locking_inset = 0;
227 sel_pos_start = sel_pos_end = inset_pos = inset_x = inset_y = 0;
228 setPos(bv->painter(), x, y);
229 sel_pos_start = sel_pos_end = cursor.pos;
230 bv->text->FinishUndo();
231 if (InsetHit(bv, x, y)) {
232 ActivateCellInset(bv, x, y, button);
234 UpdateLocal(bv, true);
235 // bv->getOwner()->getPopups().updateFormTabular();
239 void InsetTabular::InsetUnlock(BufferView * bv)
241 if (the_locking_inset) {
242 the_locking_inset->InsetUnlock(bv);
243 the_locking_inset = 0;
246 if (hasCharSelection()) {
247 sel_pos_start = sel_pos_end = cursor.pos;
248 UpdateLocal(bv, false);
250 sel_pos_start = sel_pos_end = cursor.pos;
251 no_selection = false;
254 void InsetTabular::UpdateLocal(BufferView * bv, bool flag)
257 calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE));
258 resetPos(bv->painter());
260 bv->updateInset(this, flag);
263 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
265 lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
268 if (inset == tabular->GetCellInset(actcell)) {
269 lyxerr[Debug::INSETS] << "OK" << endl;
270 the_locking_inset = tabular->GetCellInset(actcell);
271 resetPos(bv->painter());
272 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
274 inset_pos = cursor.pos;
276 } else if (the_locking_inset && (the_locking_inset == inset)) {
277 if (cursor.pos == inset_pos) {
278 lyxerr[Debug::INSETS] << "OK" << endl;
279 resetPos(bv->painter());
280 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
283 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
285 } else if (the_locking_inset) {
286 lyxerr[Debug::INSETS] << "MAYBE" << endl;
287 return the_locking_inset->LockInsetInInset(bv, inset);
289 lyxerr[Debug::INSETS] << "NOT OK" << endl;
293 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
296 if (!the_locking_inset)
298 if (the_locking_inset == inset) {
299 the_locking_inset->InsetUnlock(bv);
300 the_locking_inset = 0;
302 moveRight(bv, false);
305 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
308 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
310 if (!the_locking_inset)
312 if (the_locking_inset != inset)
313 return the_locking_inset->UpdateInsetInInset(bv, inset);
319 int InsetTabular::InsetInInsetY()
321 if (!the_locking_inset)
324 return (inset_y + the_locking_inset->InsetInInsetY());
327 void InsetTabular::InsetButtonRelease(BufferView * bv,
328 int x, int y, int button)
330 if (the_locking_inset) {
331 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
334 no_selection = false;
338 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
340 if (hasCharSelection()) {
341 sel_pos_start = sel_pos_end = 0;
342 UpdateLocal(bv, false);
344 no_selection = false;
346 int oldcell = actcell;
348 setPos(bv->painter(), x, y);
350 bool inset_hit = InsetHit(bv, x, y);
352 if ((oldcell == actcell) && the_locking_inset && inset_hit) {
353 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
355 } else if (the_locking_inset) {
356 the_locking_inset->InsetUnlock(bv);
358 the_locking_inset = 0;
359 sel_pos_start = sel_pos_end = cursor.pos;
360 sel_cell_start = sel_cell_end = actcell;
361 if (inset_hit && bv->the_locking_inset) {
362 ActivateCellInset(bv, x, y, button);
363 the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
368 bview->getOwner()->getPopups().showFormTabular();
369 else if (oldcell != actcell)
370 bview->getOwner()->getPopups().updateFormTabular();
375 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
377 if (the_locking_inset) {
378 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
379 y - inset_y, button);
383 // int oldcell = actcell,
384 int old = sel_pos_end;
386 setPos(bv->painter(), x, y);
387 sel_pos_end = cursor.pos;
388 sel_cell_end = actcell;
389 if (old != sel_pos_end)
390 UpdateLocal(bv, false);
392 if (oldcell != actcell)
393 bview->getOwner()->getPopups().updateFormTabular();
396 no_selection = false;
400 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
402 if (the_locking_inset) {
403 the_locking_inset->InsetKeyPress(xke);
409 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
412 UpdatableInset::RESULT
415 no_selection = false;
416 if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
417 || (result == DISPATCHED_NOUPDATE)) {
419 resetPos(bv->painter());
424 if ((action < 0) && arg.empty())
427 if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
428 (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
430 if (the_locking_inset) {
431 result=the_locking_inset->LocalDispatch(bv, action, arg);
432 if (result == DISPATCHED_NOUPDATE)
434 else if (result == DISPATCHED) {
435 bool upd = SetCellDimensions(bv->painter(), actcell, actrow);
436 the_locking_inset->ToggleInsetCursor(bv);
437 UpdateLocal(bv, upd);
438 the_locking_inset->ToggleInsetCursor(bv);
440 } else if (result == FINISHED) {
441 if ((action == LFUN_RIGHT) || (action == -1)) {
442 cursor.pos = inset_pos + 1;
443 resetPos(bv->painter());
453 // Normal chars not handled here
456 // --- Cursor Movements ---------------------------------------------
458 moveRight(bv, false);
459 sel_pos_end = cursor.pos;
460 UpdateLocal(bv, false);
463 result = moveRight(bv);
464 if (hasCharSelection()) {
465 sel_pos_start = sel_pos_end = cursor.pos;
466 UpdateLocal(bv, false);
468 sel_pos_start = sel_pos_end = cursor.pos;
472 sel_pos_end = cursor.pos;
473 UpdateLocal(bv, false);
476 result = moveLeft(bv);
477 if (hasCharSelection()) {
478 sel_pos_start = sel_pos_end = cursor.pos;
479 UpdateLocal(bv, false);
481 sel_pos_start = sel_pos_end = cursor.pos;
485 sel_pos_end = cursor.pos;
486 UpdateLocal(bv, false);
490 if (hasCharSelection()) {
491 sel_pos_start = sel_pos_end = cursor.pos;
492 UpdateLocal(bv, false);
494 sel_pos_start = sel_pos_end = cursor.pos;
498 sel_pos_end = cursor.pos;
499 UpdateLocal(bv, false);
503 if (hasCharSelection()) {
504 sel_pos_start = sel_pos_end = cursor.pos;
505 UpdateLocal(bv, false);
507 sel_pos_start = sel_pos_end = cursor.pos;
518 if (hasCharSelection()) {
519 sel_pos_start = sel_pos_end = cursor.pos;
520 UpdateLocal(bv, false);
522 sel_pos_start = sel_pos_end = cursor.pos;
526 result = UNDISPATCHED;
529 if (result!=FINISHED) {
530 if (!the_locking_inset) {
532 if (oldcell != actcell)
533 bview->getOwner()->getPopups().updateFormTabular();
538 bv->unlockInset(this);
543 int InsetTabular::Latex(ostream & os, bool, bool) const
545 return tabular->Latex(os);
549 int InsetTabular::Ascii(ostream &) const
554 int InsetTabular::Linuxdoc(ostream &) const
560 int InsetTabular::DocBook(ostream &) const
566 void InsetTabular::Validate(LaTeXFeatures & features) const
568 if (tabular->IsLongTabular())
569 features.longtable = true;
573 void InsetTabular::calculate_width_of_cells(Painter & pain,
574 LyXFont const & font) const
580 for(int i = 0; i < tabular->rows(); ++i) {
581 maxAsc = maxDesc = 0;
582 for(int j= 0; j < tabular->columns(); ++j) {
583 if (tabular->IsPartOfMultiColumn(i,j))
586 inset = tabular->GetCellInset(cell);
587 maxAsc = max(maxAsc, inset->ascent(pain, font));
588 maxDesc = max(maxDesc, inset->descent(pain, font));
589 tabular->SetWidthOfCell(cell, inset->width(pain, font));
591 tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
592 tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
597 void InsetTabular::GetCursorPos(int & x, int & y) const
604 void InsetTabular::ToggleInsetCursor(BufferView * bv)
606 if (the_locking_inset) {
607 the_locking_inset->ToggleInsetCursor(bv);
611 LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
613 int asc = lyxfont::maxAscent(font);
614 int desc = lyxfont::maxDescent(font);
617 bv->hideLockedInsetCursor();
619 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
620 cursor_visible = !cursor_visible;
624 void InsetTabular::ShowInsetCursor(BufferView * bv)
626 if (!cursor_visible) {
627 LyXFont font; // = GetFont(par, cursor.pos);
629 int asc = lyxfont::maxAscent(font);
630 int desc = lyxfont::maxDescent(font);
631 bv->fitLockedInsetCursor(cursor.x, cursor.y, asc, desc);
632 bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
633 cursor_visible = true;
638 void InsetTabular::HideInsetCursor(BufferView * bv)
641 ToggleInsetCursor(bv);
645 void InsetTabular::setPos(Painter & pain, int x, int y) const
647 cursor.y = cursor.pos = actcell = actrow = actcol = 0;
648 int ly = tabular->GetDescentOfRow(actrow);
650 // first search the right row
651 while((ly < y) && (actrow < tabular->rows())) {
652 cursor.y += tabular->GetDescentOfRow(actrow) +
653 tabular->GetAscentOfRow(actrow+1) +
654 tabular->GetAdditionalHeight(tabular->GetCellNumber(actcol,actrow+1));
656 ly = cursor.y + tabular->GetDescentOfRow(actrow);
658 actcell = tabular->GetCellNumber(actcol, actrow);
660 // now search the right column
661 int lx = tabular->GetWidthOfColumn(actcell) -
662 tabular->GetAdditionalWidth(actcell);
663 for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
664 ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
665 tabular->GetAdditionalWidth(actcell-1));
666 cursor.pos = ((actcell+1) * 2) - 1;
668 if ((lx - (tabular->GetWidthOfColumn(actcell)/2)) < x) {
669 cursor.x = lx + top_x - 2;
672 cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
678 void InsetTabular::resetPos(Painter & pain) const
680 actrow = cursor.y = actcol = 0;
683 for(; (cell<actcell) && !tabular->IsLastRow(cell); ++cell) {
684 if (tabular->IsLastCellInRow(cell)) {
685 cursor.y += tabular->GetDescentOfRow(actrow) +
686 tabular->GetAscentOfRow(actrow+1) +
687 tabular->GetAdditionalHeight(cell+1);
691 for(cell=actcell;!tabular->IsFirstCellInRow(cell);--cell)
693 int lx = tabular->GetWidthOfColumn(actcell);
694 for(; (cell < actcell); ++cell) {
695 lx += tabular->GetWidthOfColumn(cell);
698 cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
699 if (cursor.pos % 2) {
700 LyXFont font(LyXFont::ALL_SANE);
701 cursor.x += tabular->GetCellInset(actcell)->width(pain,font) +
702 tabular->GetBeginningOfTextInCell(actcell);
707 bool InsetTabular::SetCellDimensions(Painter & pain, int cell, int row)
709 InsetText * inset = tabular->GetCellInset(cell);
710 LyXFont font(LyXFont::ALL_SANE);
711 int asc = inset->ascent(pain, font) + ADD_TO_HEIGHT;
712 int desc = inset->descent(pain, font) + ADD_TO_HEIGHT;
713 int maxAsc = tabular->GetAscentOfRow(row);
714 int maxDesc = tabular->GetDescentOfRow(row);
715 bool ret = tabular->SetWidthOfCell(cell, inset->width(pain, font));
719 tabular->SetAscentOfRow(row, asc);
721 if (maxDesc < desc) {
723 tabular->SetDescentOfRow(row, desc);
729 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
731 if (cursor.pos % 2) { // behind the inset
733 if (actcell >= tabular->GetNumberOfCells())
737 if (ActivateCellInset(bv))
739 } else { // before the inset
742 resetPos(bv->painter());
743 return DISPATCHED_NOUPDATE;
747 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
752 if (cursor.pos % 2) { // behind the inset
754 } else if (lock) { // behind the inset
755 if (ActivateCellInset(bv, -1, -1))
758 resetPos(bv->painter());
759 return DISPATCHED_NOUPDATE;
763 UpdatableInset::RESULT InsetTabular::moveUp()
765 return DISPATCHED_NOUPDATE;
769 UpdatableInset::RESULT InsetTabular::moveDown()
771 return DISPATCHED_NOUPDATE;
775 bool InsetTabular::moveNextCell()
781 bool InsetTabular::movePrevCell()
787 bool InsetTabular::Delete()
793 void InsetTabular::SetFont(BufferView *, LyXFont const &, bool)
798 void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val)
805 setAlign = LYX_ALIGN_LEFT,
811 case LyXTabular::ALIGN_LEFT:
812 setAlign=LYX_ALIGN_LEFT;
814 case LyXTabular::ALIGN_RIGHT:
815 setAlign=LYX_ALIGN_RIGHT;
817 case LyXTabular::ALIGN_CENTER:
818 setAlign=LYX_ALIGN_CENTER;
823 if (hasCellSelection()) {
824 if (sel_cell_start > sel_cell_end) {
825 sel_pos_start = sel_cell_end;
826 sel_pos_end = sel_cell_start;
828 sel_pos_start = sel_cell_start;
829 sel_pos_end = sel_cell_end;
832 sel_pos_start = sel_pos_end = actcell;
834 case LyXTabular::SET_PWIDTH:
835 tabular->SetPWidth(actcell,val);
837 case LyXTabular::SET_SPECIAL_COLUMN:
838 case LyXTabular::SET_SPECIAL_MULTI:
839 tabular->SetAlignSpecial(actcell,val,feature);
841 case LyXTabular::APPEND_ROW:
843 // append the row into the tabular
844 tabular->AppendRow(actcell);
845 UpdateLocal(bv, true);
848 case LyXTabular::APPEND_COLUMN:
850 // append the column into the tabular
851 tabular->AppendColumn(actcell);
852 UpdateLocal(bv, true);
855 case LyXTabular::DELETE_ROW:
857 UpdateLocal(bv, true);
859 case LyXTabular::DELETE_COLUMN:
861 /* delete the column from the tabular */
862 tabular->DeleteColumn(actcell);
863 UpdateLocal(bv, true);
866 case LyXTabular::TOGGLE_LINE_TOP:
867 lineSet = !tabular->TopLine(actcell);
868 for(i=sel_pos_start; i<=sel_pos_end; ++i)
869 tabular->SetTopLine(i,lineSet);
870 UpdateLocal(bv, true);
873 case LyXTabular::TOGGLE_LINE_BOTTOM:
874 lineSet = !tabular->BottomLine(actcell);
875 for(i=sel_pos_start; i<=sel_pos_end; ++i)
876 tabular->SetBottomLine(i,lineSet);
877 UpdateLocal(bv, true);
880 case LyXTabular::TOGGLE_LINE_LEFT:
881 lineSet = !tabular->LeftLine(actcell);
882 for(i=sel_pos_start; i<=sel_pos_end; ++i)
883 tabular->SetLeftLine(i,lineSet);
884 UpdateLocal(bv, true);
887 case LyXTabular::TOGGLE_LINE_RIGHT:
888 lineSet = !tabular->RightLine(actcell);
889 for(i=sel_pos_start; i<=sel_pos_end; ++i)
890 tabular->SetRightLine(i,lineSet);
891 UpdateLocal(bv, true);
893 case LyXTabular::ALIGN_LEFT:
894 case LyXTabular::ALIGN_RIGHT:
895 case LyXTabular::ALIGN_CENTER:
896 for(i=sel_pos_start; i<=sel_pos_end; ++i)
897 tabular->SetAlignment(i,setAlign);
898 UpdateLocal(bv, true);
900 case LyXTabular::MULTICOLUMN:
902 if (tabular->row_of_cell(sel_pos_start) !=
903 tabular->row_of_cell(sel_pos_end)) {
904 WriteAlert(_("Impossible Operation!"),
905 _("Multicolumns can only be horizontally."),
909 // just multicol for one Single Cell
910 if (!hasCellSelection()) {
911 // check wether we are completly in a multicol
912 if (tabular->IsMultiColumn(actcell)) {
913 tabular->UnsetMultiColumn(actcell);
914 UpdateLocal(bv, true);
916 tabular->SetMultiColumn(actcell, 1);
917 UpdateLocal(bv, false);
921 // we have a selection so this means we just add all this
922 // cells to form a multicolumn cell
926 if (sel_pos_start > sel_pos_end) {
927 s_start = sel_pos_end;
928 s_end = sel_pos_start;
930 s_start = sel_pos_start;
933 tabular->SetMultiColumn(s_start, s_end);
934 cursor.pos = s_start;
935 sel_cell_end = sel_cell_start;
936 UpdateLocal(bv, true);
939 case LyXTabular::SET_ALL_LINES:
941 case LyXTabular::UNSET_ALL_LINES:
942 for(i=sel_pos_start; i<=sel_pos_end; ++i)
943 tabular->SetAllLines(i, setLines);
944 UpdateLocal(bv, true);
946 case LyXTabular::SET_LONGTABULAR:
947 tabular->SetLongTabular(true);
948 UpdateLocal(bv, true); // because this toggles displayed
950 case LyXTabular::UNSET_LONGTABULAR:
951 tabular->SetLongTabular(false);
952 UpdateLocal(bv, true); // because this toggles displayed
954 case LyXTabular::SET_ROTATE_TABULAR:
955 tabular->SetRotateTabular(true);
957 case LyXTabular::UNSET_ROTATE_TABULAR:
958 tabular->SetRotateTabular(false);
960 case LyXTabular::SET_ROTATE_CELL:
961 for(i=sel_pos_start; i<=sel_pos_end; ++i)
962 tabular->SetRotateCell(i,true);
964 case LyXTabular::UNSET_ROTATE_CELL:
965 for(i=sel_pos_start; i<=sel_pos_end; ++i)
966 tabular->SetRotateCell(i,false);
968 case LyXTabular::SET_LINEBREAKS:
969 what = !tabular->GetLinebreaks(actcell);
970 for(i=sel_pos_start; i<=sel_pos_end; ++i)
971 tabular->SetLinebreaks(i,what);
973 case LyXTabular::SET_LTFIRSTHEAD:
974 tabular->SetLTHead(actcell,true);
976 case LyXTabular::SET_LTHEAD:
977 tabular->SetLTHead(actcell,false);
979 case LyXTabular::SET_LTFOOT:
980 tabular->SetLTFoot(actcell,false);
982 case LyXTabular::SET_LTLASTFOOT:
983 tabular->SetLTFoot(actcell,true);
985 case LyXTabular::SET_LTNEWPAGE:
986 what = !tabular->GetLTNewPage(actcell);
987 tabular->SetLTNewPage(actcell,what);
992 void InsetTabular::RemoveTabularRow()
996 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button)
998 // the cursor.pos has to be before the inset so if it isn't now just
999 // reset the curor pos first!
1000 if (cursor.pos % 2) { // behind the inset
1002 resetPos(bv->painter());
1004 UpdatableInset * inset =
1005 static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1006 LyXFont font(LyXFont::ALL_SANE);
1008 x = inset->width(bv->painter(), font) + top_x;
1010 y = inset->descent(bv->painter(), font);
1011 inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
1013 inset->Edit(bv, x-inset_x, y-inset_y, button);
1014 if (!the_locking_inset)
1016 UpdateLocal(bv, true);
1020 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1022 InsetText * inset = tabular->GetCellInset(actcell);
1025 if (cursor.pos % 2) { // behind the inset
1026 return (((x+top_x) < cursor.x) &&
1027 ((x+top_x) > (cursor.x - inset->width(bv->painter(),
1028 LyXFont(LyXFont::ALL_SANE)))));
1030 int x2 = cursor.x + tabular->GetBeginningOfTextInCell(actcell);
1031 return ((x1 > x2) &&
1032 (x1 < (x2 + inset->width(bv->painter(),
1033 LyXFont(LyXFont::ALL_SANE)))));