From 195f2e511dc9c5e9f24623cf83910ca539e4525b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Vigna?= Date: Fri, 26 May 2000 13:09:14 +0000 Subject: [PATCH] InsetTabular should now be feature-equal to table-support, small fixes. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@775 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 17 ++ src/TabularLayout.C | 14 +- src/insets/insettabular.C | 471 +++++++++++++++++++++----------------- src/insets/insettabular.h | 4 +- src/insets/insettext.h | 2 + src/table.C | 4 +- src/tabular.C | 263 ++++++++++----------- src/tabular.h | 26 ++- 8 files changed, 424 insertions(+), 377 deletions(-) diff --git a/ChangeLog b/ChangeLog index b2df5857c5..c061d55a49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2000-05-26 Juergen Vigna + + * src/TabularLayout.C (TabularOptionsCB): removed delete-table as this + is not needed in tabular insets. + + * src/insets/insettabular.C (TabularFeatures): added missing features. + + * src/tabular.C (DeleteColumn): + (AppendColumn): + (AppendRow): implemented this functions + (cellsturct::operator=): clone the inset too; + +2000-05-23 Juergen Vigna + + * src/insets/insettabular.C (LocalDispatch): better selection support + when having multicolumn-cells. + 2000-05-26 Jose Abilio Oliveira Matos * lib/layouts/linuxdoc.layout: fix indentation of paragraphs. diff --git a/src/TabularLayout.C b/src/TabularLayout.C index 868cddcad1..0b195fc788 100644 --- a/src/TabularLayout.C +++ b/src/TabularLayout.C @@ -234,6 +234,7 @@ bool UpdateLayoutTabular(bool flag, InsetTabular *ins) } fl_set_button(fd_form_table_options->radio_rotate_table, table->GetRotateTabular()); + fl_hide_object(fd_form_table_options->button_table_delete); fl_set_focus_object(fd_form_table_options->form_table_options, fd_form_table_options->button_table_delete); } else if (fd_form_table_options->form_table_options->visible) { @@ -313,12 +314,16 @@ void TabularOptionsCB(FL_OBJECT * ob, long) num = LyXTabular::ALIGN_RIGHT; else if (ob == fd_form_table_options->radio_align_center) num = LyXTabular::ALIGN_CENTER; +#if 0 + // not needed in tabulars as you can delete them with a single delete! else if ((ob == fd_form_table_options->button_table_delete) && !Confirmed) { fl_set_object_label(fd_form_table_options->text_warning, _("Confirm: press Delete-Button again")); Confirmed = true; return; - } else if ((ob == fd_form_table_options->button_table_delete) + } +#endif + else if ((ob == fd_form_table_options->button_table_delete) && Confirmed) { num = LyXTabular::DELETE_TABULAR; Confirmed = false; @@ -409,12 +414,7 @@ void TabularOptionsCB(FL_OBJECT * ob, long) current_view->hideCursor(); inset->TabularFeatures(current_view, num, special); } - if (num == LyXTabular::DELETE_TABULAR) { - fl_set_focus_object(fd_form_table_options->form_table_options, - fd_form_table_options->button_table_delete); - fl_hide_form(fd_form_table_options->form_table_options); - } else - UpdateLayoutTabular(true, inset); + UpdateLayoutTabular(true, inset); return; } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 59ac203dee..ccaf1eb8f7 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -60,7 +60,8 @@ InsetTabular::InsetTabular(Buffer * buf, int rows, int columns) locked = no_selection = cursor_visible = false; cursor.x_fix = -1; oldcell = -1; - actcell = cursor.pos = sel_pos_start = sel_pos_end = 0; + actcell = cursor.pos = 0; + sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0; init_inset = true; } @@ -73,7 +74,8 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf) locked = no_selection = cursor_visible = false; cursor.x_fix = -1; oldcell = -1; - actcell = cursor.pos = sel_pos_start = sel_pos_end = 0; + actcell = cursor.pos = 0; + sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0; init_inset = true; } @@ -185,7 +187,7 @@ void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline, continue; cx = nx + tabular->GetBeginningOfTextInCell(cell); if (hasSelection()) - DrawCellSelection(pain, nx, baseline, i, cell); + DrawCellSelection(pain, nx, baseline, i, j, cell); tabular->GetCellInset(cell)->draw(pain, font, baseline, cx); DrawCellLines(pain, nx, baseline, i, cell); nx += tabular->GetWidthOfColumn(cell); @@ -234,27 +236,28 @@ void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline, void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline, - int row, int cell) const + int row, int column, int cell) const { - int start, end; - if (sel_cell_start > sel_cell_end) { - start = sel_cell_end; - end = sel_cell_start; - } else { - start = sel_cell_start; - end = sel_cell_end; - } - int c1 = tabular->column_of_cell(cell); - int cs = tabular->column_of_cell(start); - int ce; - if (tabular->IsLastCellInRow(end)) - ce = tabular->columns() - 1; - else - ce = tabular->column_of_cell(end+1) - 1; // because of multic. - int rs = tabular->row_of_cell(start); - int re = tabular->row_of_cell(end); + int tmp; - if ((c1 >= cs) && (c1 <= ce) && (row >= rs) && (row <= re)) { + int cs = tabular->column_of_cell(sel_cell_start); + int ce = tabular->column_of_cell(sel_cell_end); + if (cs > ce) { + ce = cs; + cs = tabular->column_of_cell(sel_cell_end); + } else { + ce = tabular->right_column_of_cell(sel_cell_end); + } + + int rs = tabular->row_of_cell(sel_cell_start); + int re = tabular->row_of_cell(sel_cell_end); + if (rs > re) { + tmp = rs; + rs = re; + re = tmp; + } + + if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) { int w = tabular->GetWidthOfColumn(cell); int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row); pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row), @@ -547,6 +550,8 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, cursor.pos = inset_pos + 1; resetPos(bv->painter()); } + sel_pos_start = sel_pos_end = cursor.pos; + sel_cell_start = sel_cell_end = actcell; the_locking_inset=0; result = DISPATCHED; return result; @@ -561,10 +566,13 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, break; // --- Cursor Movements --------------------------------------------- case LFUN_RIGHTSEL: + if (tabular->IsLastCellInRow(actcell) && !cellstart(cursor.pos)) + break; moveRight(bv, false); sel_pos_end = cursor.pos; if (!cellstart(cursor.pos)) { - if (sel_cell_start >= actcell) + if (tabular->right_column_of_cell(sel_cell_start) > + tabular->right_column_of_cell(actcell)) sel_cell_end = actcell+1; else sel_cell_end = actcell; @@ -579,10 +587,13 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, UpdateLocal(bv, false); break; case LFUN_LEFTSEL: + if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos)) + break; moveLeft(bv, false); sel_pos_end = cursor.pos; if (cellstart(cursor.pos)) { - if (sel_cell_start >= actcell) + if (tabular->column_of_cell(sel_cell_start) >= + tabular->column_of_cell(actcell)) sel_cell_end = actcell; else sel_cell_end = actcell-1; @@ -597,11 +608,18 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, UpdateLocal(bv, false); break; case LFUN_DOWNSEL: + { + int ocell = actcell; moveDown(bv); sel_pos_end = cursor.pos; - sel_cell_end = actcell; + if ((ocell == sel_cell_end) || + (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell))) + sel_cell_end = tabular->GetCellBelow(sel_cell_end); + else + sel_cell_end = tabular->GetLastCellBelow(sel_cell_end); UpdateLocal(bv, false); - break; + } + break; case LFUN_DOWN: result= moveDown(bv); sel_pos_start = sel_pos_end = cursor.pos; @@ -610,11 +628,18 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, UpdateLocal(bv, false); break; case LFUN_UPSEL: + { + int ocell = actcell; moveUp(bv); sel_pos_end = cursor.pos; - sel_cell_end = actcell; + if ((ocell == sel_cell_end) || + (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell))) + sel_cell_end = tabular->GetCellAbove(sel_cell_end); + else + sel_cell_end = tabular->GetLastCellAbove(sel_cell_end); UpdateLocal(bv, false); - break; + } + break; case LFUN_UP: result= moveUp(bv); sel_pos_start = sel_pos_end = cursor.pos; @@ -872,10 +897,10 @@ bool InsetTabular::SetCellDimensions(Painter & pain, int cell, int row) UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock) { - if (cursor.pos % 2) { // behind the inset - ++actcell; - if (actcell >= tabular->GetNumberOfCells()) + if (!cellstart(cursor.pos)) { + if (tabular->IsLastCell(actcell)) return FINISHED; + ++actcell; ++cursor.pos; } else if (lock) { if (ActivateCellInset(bv)) @@ -890,10 +915,13 @@ UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock) UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock) { - if (!cursor.pos) - return FINISHED; + if (!cursor.pos) { + if (!actcell) + return FINISHED; + cursor.pos = 2; + } --cursor.pos; - if (cursor.pos % 2) { // behind the inset + if (!cellstart(cursor.pos)) { --actcell; } else if (lock) { // behind the inset if (ActivateCellInset(bv, 0, 0, 0, true)) @@ -966,9 +994,11 @@ void InsetTabular::SetFont(BufferView *, LyXFont const &, bool) void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val) { int - i, - sel_start, - sel_end, + i, j, + sel_col_start, + sel_col_end, + sel_row_start, + sel_row_end, setLines = 0, setAlign = LYX_ALIGN_LEFT, lineSet; @@ -989,181 +1019,206 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val) break; } if (hasSelection()) { - if (sel_cell_start > sel_cell_end) { - sel_start = sel_cell_end; - sel_end = sel_cell_start; + int tmp; + sel_col_start = tabular->column_of_cell(sel_cell_start); + sel_col_end = tabular->column_of_cell(sel_cell_end); + if (sel_col_start > sel_col_end) { + sel_col_end = sel_col_start; + sel_col_start = tabular->column_of_cell(sel_cell_end); } else { - sel_start = sel_cell_start; - sel_end = sel_cell_end; + sel_col_end = tabular->right_column_of_cell(sel_cell_end); } - } else - sel_start = sel_end = actcell; - switch (feature) { - case LyXTabular::SET_PWIDTH: - { - bool update = (tabular->GetPWidth(actcell) != val); - tabular->SetPWidth(actcell,val); - if (update) - UpdateLocal(bv, true); - } - break; - case LyXTabular::SET_SPECIAL_COLUMN: - case LyXTabular::SET_SPECIAL_MULTI: - tabular->SetAlignSpecial(actcell,val,feature); - break; - case LyXTabular::APPEND_ROW: - { - // append the row into the tabular - tabular->AppendRow(actcell); - UpdateLocal(bv, true); - break; - } - case LyXTabular::APPEND_COLUMN: - { - // append the column into the tabular - tabular->AppendColumn(actcell); - UpdateLocal(bv, true); - break; - } - case LyXTabular::DELETE_ROW: - RemoveTabularRow(); - UpdateLocal(bv, true); - break; - case LyXTabular::DELETE_COLUMN: - { - /* delete the column from the tabular */ - tabular->DeleteColumn(actcell); - UpdateLocal(bv, true); - break; - } - case LyXTabular::TOGGLE_LINE_TOP: - lineSet = !tabular->TopLine(actcell); - for(i=sel_start; i<=sel_end; ++i) - tabular->SetTopLine(i,lineSet); - UpdateLocal(bv, true); - break; - - case LyXTabular::TOGGLE_LINE_BOTTOM: - lineSet = !tabular->BottomLine(actcell); - for(i=sel_start; i<=sel_end; ++i) - tabular->SetBottomLine(i,lineSet); - UpdateLocal(bv, true); - break; - - case LyXTabular::TOGGLE_LINE_LEFT: - lineSet = !tabular->LeftLine(actcell); - for(i=sel_start; i<=sel_end; ++i) - tabular->SetLeftLine(i,lineSet); - UpdateLocal(bv, true); - break; - - case LyXTabular::TOGGLE_LINE_RIGHT: - lineSet = !tabular->RightLine(actcell); - for(i=sel_start; i<=sel_end; ++i) - tabular->SetRightLine(i,lineSet); - UpdateLocal(bv, true); - break; - case LyXTabular::ALIGN_LEFT: - case LyXTabular::ALIGN_RIGHT: - case LyXTabular::ALIGN_CENTER: - for(i=sel_start; i<=sel_end; ++i) - tabular->SetAlignment(i,setAlign); - UpdateLocal(bv, true); - break; - case LyXTabular::MULTICOLUMN: - { - if (tabular->row_of_cell(sel_start) != - tabular->row_of_cell(sel_end)) { - WriteAlert(_("Impossible Operation!"), - _("Multicolumns can only be horizontally."), - _("Sorry.")); - return; - } - // just multicol for one Single Cell - if (!hasSelection()) { - // check wether we are completly in a multicol - if (tabular->IsMultiColumn(actcell)) { - tabular->UnsetMultiColumn(actcell); - UpdateLocal(bv, true); - } else { - tabular->SetMultiColumn(actcell, 1); - UpdateLocal(bv, false); - } - return; - } - // we have a selection so this means we just add all this - // cells to form a multicolumn cell - int - s_start, s_end; - - if (sel_start > sel_end) { - s_start = sel_end; - s_end = sel_start; - } else { - s_start = sel_start; - s_end = sel_end; - } - tabular->SetMultiColumn(s_start, s_end); - cursor.pos = s_start; - sel_cell_end = sel_cell_start; - UpdateLocal(bv, true); - break; - } - case LyXTabular::SET_ALL_LINES: - setLines = 1; - case LyXTabular::UNSET_ALL_LINES: - for(i=sel_start; i<=sel_end; ++i) - tabular->SetAllLines(i, setLines); - UpdateLocal(bv, true); - break; - case LyXTabular::SET_LONGTABULAR: - tabular->SetLongTabular(true); - UpdateLocal(bv, true); // because this toggles displayed - break; - case LyXTabular::UNSET_LONGTABULAR: - tabular->SetLongTabular(false); - UpdateLocal(bv, true); // because this toggles displayed - break; - case LyXTabular::SET_ROTATE_TABULAR: - tabular->SetRotateTabular(true); - break; - case LyXTabular::UNSET_ROTATE_TABULAR: - tabular->SetRotateTabular(false); - break; - case LyXTabular::SET_ROTATE_CELL: - for(i=sel_start; i<=sel_end; ++i) - tabular->SetRotateCell(i,true); - break; - case LyXTabular::UNSET_ROTATE_CELL: - for(i=sel_start; i<=sel_end; ++i) - tabular->SetRotateCell(i,false); - break; - case LyXTabular::SET_LINEBREAKS: - what = !tabular->GetLinebreaks(actcell); - for(i=sel_start; i<=sel_end; ++i) - tabular->SetLinebreaks(i,what); - break; - case LyXTabular::SET_LTFIRSTHEAD: - tabular->SetLTHead(actcell,true); - break; - case LyXTabular::SET_LTHEAD: - tabular->SetLTHead(actcell,false); - break; - case LyXTabular::SET_LTFOOT: - tabular->SetLTFoot(actcell,false); - break; - case LyXTabular::SET_LTLASTFOOT: - tabular->SetLTFoot(actcell,true); - break; - case LyXTabular::SET_LTNEWPAGE: - what = !tabular->GetLTNewPage(actcell); - tabular->SetLTNewPage(actcell,what); - break; + + sel_row_start = tabular->row_of_cell(sel_cell_start); + sel_row_end = tabular->row_of_cell(sel_cell_end); + if (sel_row_start > sel_row_end) { + tmp = sel_row_start; + sel_row_start = sel_row_end; + sel_row_end = tmp; + } + } else { + sel_col_start = sel_col_end = tabular->column_of_cell(actcell); + sel_row_start = sel_row_end = tabular->row_of_cell(actcell); } -} + bv->text->SetUndo(Undo::FINISH, + bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->previous, + bv->text->cursor.par->ParFromPos(bv->text->cursor.pos)->next); -void InsetTabular::RemoveTabularRow() -{ + int row = tabular->row_of_cell(actcell); + int column = tabular->column_of_cell(actcell); + + switch (feature) { + case LyXTabular::SET_PWIDTH: + { + bool update = (tabular->GetPWidth(actcell) != val); + tabular->SetPWidth(actcell,val); + if (update) + UpdateLocal(bv, true); + } + break; + case LyXTabular::SET_SPECIAL_COLUMN: + case LyXTabular::SET_SPECIAL_MULTI: + tabular->SetAlignSpecial(actcell,val,feature); + break; + case LyXTabular::APPEND_ROW: + // append the row into the tabular + tabular->AppendRow(actcell); + UpdateLocal(bv, true); + break; + case LyXTabular::APPEND_COLUMN: + // append the column into the tabular + tabular->AppendColumn(actcell); + actcell = tabular->GetCellNumber(row, column); + UpdateLocal(bv, true); + break; + case LyXTabular::DELETE_ROW: + tabular->DeleteRow(tabular->row_of_cell(actcell)); + if ((row+1) > tabular->rows()) + --row; + actcell = tabular->GetCellNumber(row, column); + UpdateLocal(bv, true); + break; + case LyXTabular::DELETE_COLUMN: + tabular->DeleteColumn(tabular->column_of_cell(actcell)); + if ((column+1) > tabular->columns()) + --column; + actcell = tabular->GetCellNumber(row, column); + UpdateLocal(bv, true); + break; + case LyXTabular::TOGGLE_LINE_TOP: + lineSet = !tabular->TopLine(actcell); + for(i=sel_row_start; i<=sel_row_end; ++i) + for(j=sel_col_start; j<=sel_col_end; ++j) + tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet); + UpdateLocal(bv, true); + break; + + case LyXTabular::TOGGLE_LINE_BOTTOM: + lineSet = !tabular->BottomLine(actcell); + for(i=sel_row_start; i<=sel_row_end; ++i) + for(j=sel_col_start; j<=sel_col_end; ++j) + tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet); + UpdateLocal(bv, true); + break; + + case LyXTabular::TOGGLE_LINE_LEFT: + lineSet = !tabular->LeftLine(actcell); + for(i=sel_row_start; i<=sel_row_end; ++i) + for(j=sel_col_start; j<=sel_col_end; ++j) + tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet); + UpdateLocal(bv, true); + break; + + case LyXTabular::TOGGLE_LINE_RIGHT: + lineSet = !tabular->RightLine(actcell); + for(i=sel_row_start; i<=sel_row_end; ++i) + for(j=sel_col_start; j<=sel_col_end; ++j) + tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet); + UpdateLocal(bv, true); + break; + case LyXTabular::ALIGN_LEFT: + case LyXTabular::ALIGN_RIGHT: + case LyXTabular::ALIGN_CENTER: + for(i=sel_row_start; i<=sel_row_end; ++i) + for(j=sel_col_start; j<=sel_col_end; ++j) + tabular->SetAlignment(tabular->GetCellNumber(i,j),setAlign); + UpdateLocal(bv, true); + break; + case LyXTabular::MULTICOLUMN: + { + if (sel_row_start != sel_row_end) { + WriteAlert(_("Impossible Operation!"), + _("Multicolumns can only be horizontally."), + _("Sorry.")); + return; + } + // just multicol for one Single Cell + if (!hasSelection()) { + // check wether we are completly in a multicol + if (tabular->IsMultiColumn(actcell)) { + tabular->UnsetMultiColumn(actcell); + UpdateLocal(bv, true); + } else { + tabular->SetMultiColumn(actcell, 1); + UpdateLocal(bv, false); + } + return; + } + // we have a selection so this means we just add all this + // cells to form a multicolumn cell + int + s_start, s_end; + + if (sel_cell_start > sel_cell_end) { + s_start = sel_cell_end; + s_end = sel_cell_start; + } else { + s_start = sel_cell_start; + s_end = sel_cell_end; + } + tabular->SetMultiColumn(s_start, s_end-s_start+1); + actcell = s_start; + cursor.pos = 0; + sel_cell_end = sel_cell_start; + sel_pos_end = sel_pos_start; + UpdateLocal(bv, true); + break; + } + case LyXTabular::SET_ALL_LINES: + setLines = 1; + case LyXTabular::UNSET_ALL_LINES: + for(i=sel_row_start; i<=sel_row_end; ++i) + for(j=sel_col_start; j<=sel_col_end; ++j) + tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines); + UpdateLocal(bv, true); + break; + case LyXTabular::SET_LONGTABULAR: + tabular->SetLongTabular(true); + UpdateLocal(bv, true); // because this toggles displayed + break; + case LyXTabular::UNSET_LONGTABULAR: + tabular->SetLongTabular(false); + UpdateLocal(bv, true); // because this toggles displayed + break; + case LyXTabular::SET_ROTATE_TABULAR: + tabular->SetRotateTabular(true); + break; + case LyXTabular::UNSET_ROTATE_TABULAR: + tabular->SetRotateTabular(false); + break; + case LyXTabular::SET_ROTATE_CELL: + for(i=sel_row_start; i<=sel_row_end; ++i) + for(j=sel_col_start; j<=sel_col_end; ++j) + tabular->SetRotateCell(tabular->GetCellNumber(i,j),true); + break; + case LyXTabular::UNSET_ROTATE_CELL: + for(i=sel_row_start; i<=sel_row_end; ++i) + for(j=sel_col_start; j<=sel_col_end; ++j) + tabular->SetRotateCell(tabular->GetCellNumber(i,j),false); + break; + case LyXTabular::SET_LINEBREAKS: + what = !tabular->GetLinebreaks(actcell); + for(i=sel_row_start; i<=sel_row_end; ++i) + for(j=sel_col_start; j<=sel_col_end; ++j) + tabular->SetLinebreaks(tabular->GetCellNumber(i,j),what); + break; + case LyXTabular::SET_LTFIRSTHEAD: + tabular->SetLTHead(actcell,true); + break; + case LyXTabular::SET_LTHEAD: + tabular->SetLTHead(actcell,false); + break; + case LyXTabular::SET_LTFOOT: + tabular->SetLTFoot(actcell,false); + break; + case LyXTabular::SET_LTLASTFOOT: + tabular->SetLTFoot(actcell,true); + break; + case LyXTabular::SET_LTNEWPAGE: + what = !tabular->GetLTNewPage(actcell); + tabular->SetLTNewPage(actcell,what); + break; + } } bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button, diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index e613bfe66e..e4534f480e 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -153,8 +153,8 @@ private: void DrawCellLines(Painter &, int x, int baseline, int row, int cell) const; /// - void DrawCellSelection(Painter &, int x, int baseline, int row, int cell) - const; + void DrawCellSelection(Painter &, int x, int baseline, + int row, int column, int cell) const; /// void ShowInsetCursor(BufferView *); /// diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 8107cba39e..e6544af41d 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -121,6 +121,8 @@ public: void SetFrameColor(LColor::color); /// void computeTextRows(Painter &) const; + /// + Buffer * BufferOwner() const { return buffer; } LyXParagraph * par; diff --git a/src/table.C b/src/table.C index bd12c5fe26..41098e6e2b 100644 --- a/src/table.C +++ b/src/table.C @@ -1367,8 +1367,8 @@ int LyXTable::TexEndOfCell(ostream & os, int cell) os << "\\multicolumn{" << cells_in_multicolumn(nvcell) << "}{"; - if (!cellinfo_of_cell(cell+1)->align_special.empty()) { - os << cellinfo_of_cell(cell+1)->align_special + if (!cellinfo_of_cell(nvcell)->align_special.empty()) { + os << cellinfo_of_cell(nvcell)->align_special << "}{"; } else { if (LeftLine(nvcell)) diff --git a/src/tabular.C b/src/tabular.C index eae3289e05..0d05fddbb2 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -73,6 +73,8 @@ LyXTabular::cellstruct::cellstruct(cellstruct const & cs) rotate = cs.rotate; linebreaks = cs.linebreaks; inset = 0; +// if (cs.inset) +// inset = static_cast(cs.inset->Clone()); } @@ -87,6 +89,8 @@ LyXTabular::cellstruct::operator=(cellstruct const & cs) bottom_line = cs.bottom_line; rotate = cs.rotate; linebreaks = cs.linebreaks; + if (cs.inset) + inset = static_cast(cs.inset->Clone()); return *this; } @@ -203,7 +207,8 @@ void LyXTabular::Init(int rows_arg, int columns_arg) // Jürgen, use iterators. for (i = 0; i < rows_; ++i) { for (j = 0; j < columns_; ++j) { - cell_info[i][j].inset = new InsetText(owner_->BufferOwner()); + if (!cell_info[i][j].inset) + cell_info[i][j].inset = new InsetText(owner_->BufferOwner()); cell_info[i][j].inset->setOwner(owner_); cell_info[i][j].inset->SetDrawLockedFrame(true); cell_info[i][j].cellno = cellno++; @@ -231,146 +236,113 @@ void LyXTabular::Init(int rows_arg, int columns_arg) } -void LyXTabular::AppendRow(int /* cell */) +void LyXTabular::AppendRow(int cell ) { -#if 0 - int row = row_of_cell(cell); - rowstruct * row_info2 = new rowstruct[rows_ + 1]; - cellstruct ** cell_info2 = new cellstruct * [rows_ + 1]; - int i; +// cell_vector::iterator cit = cell_info.begin() + row; +// cell_info.insert(cit, vector(columns_, cellstruct())); +// cell_info.insert(cell_info.begin(), vector(columns_, cellstruct())); - for (i = 0; i <= row; ++i) { - cell_info2[i] = cell_info[i]; - row_info2[i] = row_info[i]; - } - for (i = rows_ - 1; i >= row; --i) { - cell_info2[i + 1] = cell_info[i]; - row_info2[i + 1] = row_info[i]; - } - row_info2[row + 1].top_line = row_info[i].top_line; - cell_info2[row + 1] = new cellstruct[columns_](owner_->BufferOwner()); - for (i = 0; i < columns_; ++i) { - cell_info2[row + 1][i].width_of_cell = 0; - cell_info2[row + 1][i] = cell_info2[row][i]; - } - - delete[] cell_info; - cell_info = cell_info2; - delete[] row_info; - row_info = row_info2; - ++rows_; +// row_vector r_info = row_vector(rows_, rowstruct()); + + cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_, + cellstruct())); + int row = row_of_cell(cell); + int i; + + row_vector::iterator rit = row_info.begin() + row; + row_info.insert(rit, rowstruct()); + + for(i = 0; i <= row; ++i) { +// r_info[i] = row_info[i]; + for(int j = 0; j < columns_; ++j) { + c_info[i][j] = cell_info[i][j]; + } + } + for(i = row+1; i < rows_; ++i) { +// r_info[i] = row_info[i-1]; + for(int j = 0; j < columns_; ++j) { + c_info[i][j] = cell_info[i-1][j]; + } + } +// row_info = r_info; + cell_info = c_info; + for(i = 0; i < rows_; ++i) { + for(int j = 0; j < columns_; ++j) { + cell_info[i][j].inset = static_cast(c_info[i][j].inset->Clone()); + } + } + ++row; + for (int j = 0; j < columns_; ++j) { + cell_info[row][j].inset->clear(); + } Reinit(); -#endif } void LyXTabular::DeleteRow(int row) { - row_info.erase(row_info.begin() + row); //&row_info[row]); - cell_info.erase(cell_info.begin() + row); //&cell_info[row]); - --rows_; - Reinit(); + if (!(rows_ - 1)) + return; + row_info.erase(row_info.begin() + row); //&row_info[row]); + cell_info.erase(cell_info.begin() + row); //&cell_info[row]); + --rows_; + Reinit(); } -void LyXTabular::AppendColumn(int /*cell*/) +void LyXTabular::AppendColumn(int cell) { -#if 0 - int j; - columnstruct * column_info2 = new columnstruct[columns_ + 1]; - int column = right_column_of_cell(cell); + ++columns_; + + cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_, + cellstruct())); + int column = column_of_cell(cell); + int i, j; + column_vector::iterator cit = column_info.begin() + column; + column_info.insert(cit, columnstruct()); - int i = 0; - for (; i <= column; ++i) { - column_info2[i] = column_info[i]; - } - for (i = columns_ - 1; i >= column; --i) { - column_info2[i + 1] = column_info[i]; - } - - delete[] column_info; - column_info = column_info2; - for (i = 0; i < rows_; ++i) { - cellstruct * tmp = cell_info[i]; - cell_info[i] = new cellstruct[columns_ + 1](owner_->BufferOwner()); for (j = 0; j <= column; ++j) { - cell_info[i][j] = tmp[j]; + c_info[i][j] = cell_info[i][j]; } - for (j = column; j < columns_; ++j) { - cell_info[i][j + 1] = tmp[j]; + for (j = column+1; j < columns_; ++j) { + c_info[i][j] = cell_info[i][j-1]; } // care about multicolumns - if (cell_info[i][column + 1].multicolumn - == LyXTabular::CELL_BEGIN_OF_MULTICOLUMN){ - cell_info[i][column + 1].multicolumn = - LyXTabular::CELL_PART_OF_MULTICOLUMN; + if (cell_info[i][column+1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) { + cell_info[i][column+1].multicolumn = CELL_PART_OF_MULTICOLUMN; } - if (column + 1 == columns_ - || cell_info[i][column + 2].multicolumn - != LyXTabular::CELL_PART_OF_MULTICOLUMN){ - cell_info[i][column + 1].multicolumn = - LyXTabular::CELL_NORMAL; + if (((column+1) == columns_) || + (cell_info[i][column+2].multicolumn != CELL_PART_OF_MULTICOLUMN)) { + cell_info[i][column+1].multicolumn = LyXTabular::CELL_NORMAL; } - delete[] tmp; } - - ++columns_; - Reinit(); -#endif -} - - -void LyXTabular::DeleteColumn(int /*cell*/) -{ -#if 0 - int column1 = column_of_cell(cell); - int column2 = right_column_of_cell(cell); - - if (column1 == 0 && column2 == columns_ - 1) - return; - - for (int column = column1; column <= column2; ++column) { - delete_column(column1); + cell_info = c_info; + for(i = 0; i < rows_; ++i) { + for(j = 0; j < columns_; ++j) { + cell_info[i][j].inset = static_cast(c_info[i][j].inset->Clone()); + } } - Reinit(); -#endif -} - - -void LyXTabular::delete_column(int /*column*/) -{ -#if 0 - int i, j; - columnstruct * column_info2 = new columnstruct[columns_-1]; - - for (i = 0; i < column; ++i) { - column_info2[i] = column_info[i]; - } - for (i = column; i < columns_ - 1; ++i) { - column_info2[i] = column_info[i + 1]; - } - - delete[] column_info; - column_info = column_info2; - + ++column; for (i = 0; i < rows_; ++i) { - cellstruct * tmp = cell_info[i]; - cell_info[i] = new cellstruct[columns_ - 1](owner_->BufferOwner()); - for (j = 0; j < column; ++j) { - cell_info[i][j] = tmp[j]; - } - for (j = column; j < columns_ - 1; ++j) { - cell_info[i][j] = tmp[j + 1]; - } - delete[] tmp; + cell_info[i][column].inset->clear(); } + Reinit(); +} + +void LyXTabular::DeleteColumn(int column) +{ + if (!(columns_ - 1)) + return; + column_info.erase(column_info.begin() + column); + for (int i = 0; i < rows_; ++i) { + cell_info[i].erase(cell_info[i].begin() + column); + } --columns_; Reinit(); -#endif } @@ -462,25 +434,6 @@ int LyXTabular::NumberOfCellsInRow(int cell) const } -int LyXTabular::AppendCellAfterCell(int append_cell, int question_cell) -{ - return (right_column_of_cell(append_cell) == - right_column_of_cell(question_cell)); -} - - -int LyXTabular::DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell) -{ - if (column_of_cell(delete_column_cell) == 0 && - right_column_of_cell(delete_column_cell) == columns_ - 1) - return 0; - else - return - (column_of_cell(cell) >= column_of_cell(delete_column_cell) && - column_of_cell(cell) <= right_column_of_cell(delete_column_cell)); -} - - /* returns 1 if there is a topline, returns 0 if not */ bool LyXTabular::TopLine(int cell) const { @@ -1561,19 +1514,14 @@ LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const void LyXTabular::SetMultiColumn(int cell, int number) { - int new_width = cellinfo_of_cell(cell)->width_of_cell; - - cellinfo_of_cell(cell)->multicolumn = LyXTabular::CELL_BEGIN_OF_MULTICOLUMN; + cellinfo_of_cell(cell)->multicolumn = CELL_BEGIN_OF_MULTICOLUMN; cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment; cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line; cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line; for (number--; number > 0; --number) { - cellinfo_of_cell(cell+number)->multicolumn = - LyXTabular::CELL_PART_OF_MULTICOLUMN; - new_width += cellinfo_of_cell(cell+number)->width_of_cell; + cellinfo_of_cell(cell+number)->multicolumn = CELL_PART_OF_MULTICOLUMN; } set_row_column_number_info(); - SetWidthOfCell(cell, new_width); } @@ -1583,8 +1531,9 @@ int LyXTabular::cells_in_multicolumn(int cell) const int column = column_of_cell(cell); int result = 1; ++column; - while (column < columns_ && cell_info[row][column].multicolumn - == LyXTabular::CELL_PART_OF_MULTICOLUMN){ + while ((column < columns_) && + cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN) + { ++result; ++column; } @@ -1599,15 +1548,13 @@ int LyXTabular::UnsetMultiColumn(int cell) int result = 0; - if (cell_info[row][column].multicolumn - == LyXTabular::CELL_BEGIN_OF_MULTICOLUMN){ - cell_info[row][column].multicolumn = LyXTabular::CELL_NORMAL; + if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) { + cell_info[row][column].multicolumn = CELL_NORMAL; ++column; - while (column < columns_ && - cell_info[row][column].multicolumn - == LyXTabular::CELL_PART_OF_MULTICOLUMN){ - cell_info[row][column].multicolumn = - LyXTabular::CELL_NORMAL; + while ((column < columns_) && + (cell_info[row][column].multicolumn ==CELL_PART_OF_MULTICOLUMN)) + { + cell_info[row][column].multicolumn = CELL_NORMAL; ++column; ++result; } @@ -1691,6 +1638,26 @@ int LyXTabular::GetCellBelow(int cell) const } +int LyXTabular::GetLastCellAbove(int cell) const +{ + if (row_of_cell(cell) <= 0) + return cell; + if (!IsMultiColumn(cell)) + return GetCellAbove(cell); + return cell_info[row_of_cell(cell)-1][right_column_of_cell(cell)].cellno; +} + + +int LyXTabular::GetLastCellBelow(int cell) const +{ + if (row_of_cell(cell)+1 >= rows_) + return cell; + if (!IsMultiColumn(cell)) + return GetCellBelow(cell); + return cell_info[row_of_cell(cell)+1][right_column_of_cell(cell)].cellno; +} + + int LyXTabular::GetCellNumber(int row, int column) const { if (column >= columns_) diff --git a/src/tabular.h b/src/tabular.h index 2d407fe9e2..5430545b83 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -167,10 +167,6 @@ public: /// int GetNumberOfCells() const; /// - int AppendCellAfterCell(int append_cell, int question_cell); - /// - int DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell); - /// int NumberOfCellsInRow(int cell) const; /// void Write(std::ostream &) const; @@ -209,6 +205,8 @@ public: /// int column_of_cell(int cell) const; /// + int right_column_of_cell(int cell) const; + /// void SetLongTabular(int what); /// bool IsLongTabular() const; @@ -229,6 +227,10 @@ public: /// int GetCellBelow(int cell) const; /// + int GetLastCellAbove(int cell) const; + /// + int GetLastCellBelow(int cell) const; + /// int GetCellNumber(int row, int column) const; /// void SetLinebreaks(int cell, bool what); @@ -297,6 +299,9 @@ private: ////////////////////////////////////////////////////////////////// /// InsetText * inset; }; + typedef std::vector cell_vector; + typedef std::vector cell_vvector; + /// struct rowstruct { /// @@ -313,6 +318,8 @@ private: ////////////////////////////////////////////////////////////////// /// This are for longtabulars only bool newpage; }; + typedef std::vector row_vector; + /// struct columnstruct { /// @@ -329,6 +336,8 @@ private: ////////////////////////////////////////////////////////////////// string p_width; string align_special; }; + typedef std::vector column_vector; + /// int rows_; /// @@ -340,11 +349,11 @@ private: ////////////////////////////////////////////////////////////////// /// int * columnofcell; /// - std::vector row_info; + row_vector row_info; /// - std::vector column_info; + column_vector column_info; /// - mutable std::vector< std::vector > cell_info; + mutable cell_vvector cell_info; /// int width_of_tabular; /// @@ -372,9 +381,6 @@ private: ////////////////////////////////////////////////////////////////// /// void calculate_width_of_tabular(); - /// - int right_column_of_cell(int cell) const; - /// cellstruct * cellinfo_of_cell(int cell) const;