From 9f509a68167d75f0caafe437a0fd6a92bc6ffed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Vigna?= Date: Tue, 16 May 2000 15:17:19 +0000 Subject: [PATCH] Fixed undo handling for tabular-insets and update TabularLayout on cursor move. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@734 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 18 +++++++++++ src/TableLayout.C | 4 ++- src/TabularLayout.C | 35 ++++++++++++---------- src/insets/insettabular.C | 52 ++++++++++++++++++++++++-------- src/insets/insettabular.h | 2 ++ src/insets/insettext.C | 1 + src/tabular.C | 63 ++++++++------------------------------- 7 files changed, 96 insertions(+), 79 deletions(-) diff --git a/ChangeLog b/ChangeLog index ed6ba4cbe6..b8d903176d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2000-05-16 Juergen Vigna + + * src/insets/insettabular.C (UnlockInsetInInset): Changes to update + the TabularLayout on cursor move. + + * src/TabularLayout.C (TabularOptionsCB): Wrong call to MenuLayoutTable + + * src/insets/insettabular.C (Clone): Clone the LyXTabular for + undo-handling. + (getCellXPos): + (draw): fixed cursor position and drawing so that the cursor is + visible when before the tabular-inset. + + * src/insets/insettext.C (init): drawLockedFrame was not initialized + when creating from old insettext. + + * src/tabular.C (Clone): added Clone of text-inset for undo-handling. + 2000-05-15 Jean-Marc Lasgouttes * lib/tex/hollywood.cls: better algorithm for page breaks (Garst) diff --git a/src/TableLayout.C b/src/TableLayout.C index 56ae4832af..5a16d3d6b1 100644 --- a/src/TableLayout.C +++ b/src/TableLayout.C @@ -15,6 +15,7 @@ #include "gettext.h" #include "lyxtext.h" #include "layout.h" +#include "insets/lyxinset.h" // Prototypes @@ -40,7 +41,8 @@ static int extra_col_cursor_x; // need no y's, one-line input fields static int extra_multicol_cursor_x; // Joacim -#define IS_TABULAR (current_view->the_locking_inset != 0) +#define IS_TABULAR (current_view->the_locking_inset && \ + current_view->the_locking_inset->GetFirstLockingInsetOfType(Inset::TABULAR_CODE)) bool UpdateLayoutTable(int flag) { diff --git a/src/TabularLayout.C b/src/TabularLayout.C index 7bd052fa59..868cddcad1 100644 --- a/src/TabularLayout.C +++ b/src/TabularLayout.C @@ -24,7 +24,7 @@ extern FD_form_table_extra * fd_form_table_extra; extern BufferView * current_view; extern void OpenLayoutTableExtra(); -extern bool UpdateLayoutTabular(bool); +extern bool UpdateLayoutTabular(bool, InsetTabular *); static int Confirmed = false; static int ActCell; @@ -46,23 +46,25 @@ void MenuLayoutTabular(bool flag, InsetTabular * ins) inset = ins; if (!inset) return; - if (UpdateLayoutTabular(flag)) { + if (UpdateLayoutTabular(flag, ins)) { if (fd_form_table_options->form_table_options->visible) { fl_raise_form(fd_form_table_options->form_table_options); } else { fl_show_form(fd_form_table_options->form_table_options, FL_PLACE_MOUSE, FL_FULLBORDER, - _("Table Layout")); + _("Tabular Layout")); } } } -bool UpdateLayoutTabular(bool flag) +bool UpdateLayoutTabular(bool flag, InsetTabular *ins) { - if (!inset) + if (!ins) return false; + inset = ins; + bool update = true; if (!current_view->available()) update = false; @@ -245,10 +247,9 @@ bool UpdateLayoutTabular(bool flag) void TabularOptionsCB(FL_OBJECT * ob, long) { - if (!inset) { - MenuLayoutTable(0); + if (!inset) return; - } + int s, num = 0; string special, str; @@ -256,7 +257,7 @@ void TabularOptionsCB(FL_OBJECT * ob, long) int cell = inset->GetActCell(); if (ActCell != cell) { - MenuLayoutTable(0); + MenuLayoutTabular(false, inset); fl_set_object_label(fd_form_table_options->text_warning, _("Warning: Wrong Cursor position, updated window")); fl_show_object(fd_form_table_options->text_warning); @@ -268,7 +269,7 @@ void TabularOptionsCB(FL_OBJECT * ob, long) // No point in processing directives that you can't do anything with // anyhow, so exit now if the buffer is read-only. if (current_view->buffer()->isReadonly()) { - MenuLayoutTable(0); + MenuLayoutTabular(false, inset); return; } @@ -406,18 +407,14 @@ void TabularOptionsCB(FL_OBJECT * ob, long) return; if (current_view->available()) { current_view->hideCursor(); -// if ((num == LyXTabular::SET_SPECIAL_COLUMN) || -// (num == LyXTabular::SET_SPECIAL_MULTI)) inset->TabularFeatures(current_view, num, special); -// else -// inset->TabularFeatures(num); } 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); + UpdateLayoutTabular(true, inset); return; } @@ -441,6 +438,12 @@ void SetPWidthTabularCB(FL_OBJECT * ob, long) current_view->hideCursor(); inset->TabularFeatures(current_view, LyXTabular::SET_PWIDTH, str); } - MenuLayoutTable(0); // update for alignment + MenuLayoutTabular(false, inset); // update for alignment } } + +void TabularOptClose() +{ + inset = 0; +} + diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index ca22dd95b4..47872cd565 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -33,6 +33,8 @@ #include "insets/insettext.h" extern void MenuLayoutTabular(bool, InsetTabular *); +extern bool UpdateLayoutTabular(bool, InsetTabular *); +extern void TabularOptClose(); const int ADD_TO_HEIGHT = 2; const int ADD_TO_TABULAR_WIDTH = 2; @@ -54,10 +56,10 @@ InsetTabular::InsetTabular(Buffer * buf, int rows, int columns) // for now make it always display as display() inset // just for test!!! the_locking_inset = 0; - cursor_visible = false; + locked = no_selection = cursor_visible = false; cursor.x_fix = -1; + oldcell = -1; actcell = cursor.pos = sel_pos_start = sel_pos_end = 0; - no_selection = false; init_inset = true; } @@ -67,10 +69,10 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf) buffer = buf; // set this first tabular = new LyXTabular(this, *(tab.tabular)); the_locking_inset = 0; - cursor_visible = false; + locked = no_selection = cursor_visible = false; cursor.x_fix = -1; + oldcell = -1; actcell = cursor.pos = sel_pos_start = sel_pos_end = 0; - no_selection = false; init_inset = true; } @@ -84,6 +86,8 @@ InsetTabular::~InsetTabular() Inset * InsetTabular::Clone() const { InsetTabular * t = new InsetTabular(*this, buffer); + delete t->tabular; + t->tabular = tabular->Clone(t); return t; } @@ -168,6 +172,7 @@ void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline, resetPos(pain); reinit = true; } + x += ADD_TO_TABULAR_WIDTH; for(i=0;irows();++i) { nx = int(x); for(j=0;jcolumns();++j) { @@ -235,6 +240,7 @@ void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button) lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl; return; } + locked = true; the_locking_inset = 0; sel_pos_start = sel_pos_end = inset_pos = inset_x = inset_y = 0; setPos(bv->painter(), x, y); @@ -250,6 +256,7 @@ void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button) void InsetTabular::InsetUnlock(BufferView * bv) { + TabularOptClose(); if (the_locking_inset) { the_locking_inset->InsetUnlock(bv); the_locking_inset = 0; @@ -261,6 +268,8 @@ void InsetTabular::InsetUnlock(BufferView * bv) } else sel_pos_start = sel_pos_end = cursor.pos; no_selection = false; + oldcell = -1; + locked = false; } void InsetTabular::UpdateLocal(BufferView * bv, bool flag) @@ -277,6 +286,7 @@ bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset) lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <GetCellInset(actcell)) { lyxerr[Debug::INSETS] << "OK" << endl; the_locking_inset = tabular->GetCellInset(actcell); @@ -314,7 +324,16 @@ bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset, moveRight(bv, false); return true; } - return the_locking_inset->UnlockInsetInInset(bv, inset, lr); + if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) { + if ((inset->LyxCode() == TABULAR_CODE) && + !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) + { + UpdateLayoutTabular(true, const_cast(this)); + oldcell = actcell; + } + return true; + } + return false; } bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset) @@ -391,13 +410,13 @@ void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button) } no_selection = false; - int oldcell = actcell; + int ocell = actcell; setPos(bv->painter(), x, y); bool inset_hit = InsetHit(bv, x, y); - if ((oldcell == actcell) && the_locking_inset && inset_hit) { + if ((ocell == actcell) && the_locking_inset && inset_hit) { the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button); return; } else if (the_locking_inset) { @@ -414,7 +433,7 @@ void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button) #if 0 if (button == 3) bview->getOwner()->getPopups().showFormTabular(); - else if (oldcell != actcell) + else if (ocell != actcell) bview->getOwner()->getPopups().updateFormTabular(); #endif } @@ -428,7 +447,7 @@ void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button) return; } if (!no_selection) { - // int oldcell = actcell, + // int ocell = actcell, int old = sel_pos_end; setPos(bv->painter(), x, y); @@ -437,7 +456,7 @@ void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button) if (old != sel_pos_end) UpdateLocal(bv, false); #if 0 - if (oldcell != actcell) + if (ocell != actcell) bview->getOwner()->getPopups().updateFormTabular(); #endif } @@ -583,7 +602,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, if (result!=FINISHED) { if (!the_locking_inset) { #if 0 - if (oldcell != actcell) + if (ocell != actcell) bview->getOwner()->getPopups().updateFormTabular(); #endif ShowInsetCursor(bv); @@ -739,11 +758,14 @@ int InsetTabular::getCellXPos(int cell) const for(; (c < cell); ++c) { lx += tabular->GetWidthOfColumn(c); } - return (lx - tabular->GetWidthOfColumn(cell) + top_x); + return (lx - tabular->GetWidthOfColumn(cell) + top_x + + ADD_TO_TABULAR_WIDTH); } void InsetTabular::resetPos(Painter & pain) const { + if (!locked) + return; actcol = tabular->column_of_cell(actcell); int cell = 0; @@ -762,6 +784,12 @@ void InsetTabular::resetPos(Painter & pain) const cursor.x += tabular->GetCellInset(actcell)->width(pain,font) + tabular->GetBeginningOfTextInCell(actcell); } + if ((!the_locking_inset || + !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) && + (actcell != oldcell)) { + UpdateLayoutTabular(true, const_cast(this)); + oldcell = actcell; + } } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 277988a4c0..9de5b92af8 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -204,9 +204,11 @@ private: sel_cell_start, sel_cell_end, actcell, + oldcell, actcol, actrow; bool + locked, no_selection; mutable bool init_inset; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 43d55e59be..c68e1296f0 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -84,6 +84,7 @@ void InsetText::init(Buffer * buf, InsetText const * ins) if (ins) { SetParagraphData(ins->par); autoBreakRows = ins->autoBreakRows; + drawLockedFrame = ins->drawLockedFrame; } par->SetInsetOwner(this); cursor.par = par; diff --git a/src/tabular.C b/src/tabular.C index 8966171910..29322c35f0 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -97,23 +97,6 @@ LyXTabular::rowstruct::rowstruct() } -// Nothing to do, but gcc 2.7.2.3 wants one... (JMarc) -//LyXTabular::rowstruct::~rowstruct() -//{} - - -//LyXTabular::rowstruct & -// LyXTabular::rowstruct::operator=(rowstruct const & rs) -//{ -// top_line = rs.top_line; -// bottom_line = rs.bottom_line; -// ascent_of_row = rs.ascent_of_row; -// descent_of_row = rs.descent_of_row; -// newpage = rs.newpage; -// return *this; -//} - - LyXTabular::columnstruct::columnstruct() { left_line = true; @@ -123,24 +106,6 @@ LyXTabular::columnstruct::columnstruct() } -//LyXTabular::columnstruct::~columnstruct() -//{ -//} - - -//LyXTabular::columnstruct & -// LyXTabular::columnstruct::operator=(columnstruct const & cs) -//{ -// left_line = cs.left_line; -// right_line = cs.right_line; -// alignment = cs.alignment; -// width_of_column = cs.width_of_column; -// p_width = cs.p_width; -// align_special = cs.align_special; -// return *this; -//} - - /* konstruktor */ LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg) { @@ -179,24 +144,9 @@ LyXTabular & LyXTabular::operator=(LyXTabular const & lt) // call abort() Assert(rows_ == lt.rows_ && columns_ == lt.columns_); -// int row = 0, column = 0; - cell_info = lt.cell_info; -// for (row = 0; row < rows_; ++row) { -// for (column = 0; column < columns_; ++column) { -// cell_info[row][column] = lt.cell_info[row][column]; -// } -// } - row_info = lt.row_info; -// for (row = 0; row < rows_; ++row) { -// row_info[row] = lt.row_info[row]; -// } - column_info = lt.column_info; -// for (column = 0; column < columns_; ++column) { -// column_info[column] = lt.column_info[column]; -// } // long tabular stuff SetLongTabular(lt.is_long_tabular); @@ -216,6 +166,19 @@ LyXTabular & LyXTabular::operator=(LyXTabular const & lt) LyXTabular * LyXTabular::Clone(InsetTabular * inset) { LyXTabular * result = new LyXTabular(inset, *this); + /// + // don't know if this is good but I need to Clone also + // the text-insets here, this is for the Undo-facility! + /// + int i,j; + for(i=0; i < rows_; ++i) { + for(j=0; j < columns_; ++j) { + delete result->cell_info[i][j].inset; + result->cell_info[i][j].inset=new InsetText(*cell_info[i][j].inset, + inset->BufferOwner()); + result->cell_info[i][j].inset->setOwner(inset); + } + } return result; }