diff --git a/ChangeLog b/ChangeLog index 0c6b6752f0..0af405563c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2001-01-03 Juergen Vigna + + * src/insets/insettabular.C (InsetButtonPress): look for button==2 + and do Clipboard Paste! + + * src/insets/insettext.C (SetText): added function. + + * src/insets/insettabular.C (LocalDispatch): Fixed LFUN_PASTE and + new LFUN_PASTESELECTION. + + * src/insets/insettext.C (draw): don't clear if top_x changes. + + * src/insets/insettabular.C (draw): clear only if the inset didn't + change in the draw routine. + + * src/insets/insettext.C (width): make the width dependant on the + textWidth too. + + * src/text.C (draw): comment out the UpdateInset call. + + * src/screen.C (DrawOneRow): + (DrawFromTo): check for bv->text->status not text->status. + + * src/insets/insettabular.C (calculate_dimensions_of_cells): calculate + dimensions of ascent-descent for the whole row. + + * src/insets/insettext.C (draw): check also for need_update == INIT. + 2001-01-03 Jean-Marc Lasgouttes * Makefile.am (EXTRA_DIST): add autogen.sh diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index e811f13527..3ad866ed13 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -35,6 +35,7 @@ #include "frontends/Dialogs.h" #include "debug.h" #include "lyxfunc.h" +#include "WorkArea.h" const int ADD_TO_HEIGHT = 2; const int ADD_TO_TABULAR_WIDTH = 2; @@ -50,6 +51,7 @@ using std::ifstream; using std::max; using std::endl; using std::swap; +using std::max; struct tabular_features { @@ -225,7 +227,6 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, Painter & pain = bv->painter(); int i, j; int nx; - float cx; UpdatableInset::draw(bv, font, baseline, x, cleared); if (!cleared && ((need_update == INIT) || (need_update == FULL) || @@ -253,6 +254,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, x += ADD_TO_TABULAR_WIDTH; if (cleared) { int cell = 0; + float cx; for (i = 0; i < tabular->rows(); ++i) { nx = int(x); dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) && @@ -319,10 +321,10 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n"; return; } +// LyXText::text_status st = bv->text->status; #if 0 - LyXText::text_status st = bv->text->status; do { - cx = nx + tabular->GetBeginningOfTextInCell(cell); + float cx = nx + tabular->GetBeginningOfTextInCell(cell); bv->text->status = st; if (need_update == CELL) { // clear before the inset @@ -346,7 +348,13 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, tabular->GetCellInset(cell)->draw(bv,font,baseline, cx, false); } while(bv->text->status == LyXText::CHANGED_IN_DRAW); #else - cx = nx + tabular->GetBeginningOfTextInCell(cell); + float dx; + float cx; + cx = dx = nx + tabular->GetBeginningOfTextInCell(cell); + tabular->GetCellInset(cell)->draw(bv,font,baseline, dx, false); + if (bv->text->status == LyXText::CHANGED_IN_DRAW) + return; + // clear only if we didn't have a change if (need_update == CELL) { // clear before the inset pain.fillRectangle( @@ -366,9 +374,6 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, tabular->GetAscentOfRow(i) + tabular->GetDescentOfRow(i) - 1); } - tabular->GetCellInset(cell)->draw(bv,font,baseline, cx, false); - if (bv->text->status == LyXText::CHANGED_IN_DRAW) - return; #endif } x -= ADD_TO_TABULAR_WIDTH; @@ -687,6 +692,10 @@ void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button) the_locking_inset->InsetUnlock(bv); } the_locking_inset = 0; + if (button == 2) { + LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph"); + return; + } if (inset_hit && bv->theLockingInset()) { if (ActivateCellInset(bv, x, y, button)) the_locking_inset->InsetButtonPress(bv, x - inset_x, @@ -954,21 +963,85 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action, bv->text->FinishUndo(); copySelection(bv); break; - case LFUN_PASTE: - if (!hasPasteBuffer()) + case LFUN_PASTESELECTION: + { + string clip(bv->workarea()->getClipboard()); + + if (clip.empty()) break; - bv->text->SetUndo(bv->buffer(), Undo::INSERT, + if (clip.find('\t') != string::npos) { + int cols = 0; + int rows = 0; + int maxCols = 0; + string::size_type p = 0; + + while((p < clip.length()) && + (p = clip.find_first_of("\t\n", p)) != string::npos) + { + switch(clip[p]) { + case '\t': + ++cols; + break; + case '\n': + ++rows; + maxCols = max(cols+1, maxCols); + cols = 0; + break; + } + ++p; + } + delete paste_tabular; + paste_tabular = new LyXTabular(this, rows+1, maxCols); + string::size_type op = 0; + int cell = 0; + unsigned int len = clip.length(); + int cells = paste_tabular->GetNumberOfCells(); + p = cols = 0; + while((cell < cells) && (p < len) && + (p = clip.find_first_of("\t\n", p)) != string::npos) + { + switch(clip[p]) { + case '\t': + paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op)); + ++cols; + ++cell; + break; + case '\n': + paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op)); + while(cols++ < maxCols) + ++cell; + cols = 0; + break; + } + op = p + 1; + ++p; + } + // check for the last cell if there is no trailing '\n' + if ((cell < cells) && ((op-1) < len)) + paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op)); + } else { + // so that the clipboard is used and it goes on to default + // and executes LFUN_PASTESELECTION in insettext! + delete paste_tabular; + paste_tabular = 0; + } + } + case LFUN_PASTE: + if (hasPasteBuffer()) { + bv->text->SetUndo(bv->buffer(), Undo::INSERT, #ifndef NEW_INSETS - bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, - bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next + bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, + bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next #else - bv->text->cursor.par()->previous, - bv->text->cursor.par()->next + bv->text->cursor.par()->previous, + bv->text->cursor.par()->next #endif ); - pasteSelection(bv); - UpdateLocal(bv, INIT, true); - break; + pasteSelection(bv); + UpdateLocal(bv, INIT, true); + break; + } + // ATTENTION: the function above has to be PASTE and PASTESELECTION!!! default: // we try to activate the actual inset and put this event down to // the insets dispatch function. @@ -1037,7 +1110,8 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const { int cell = -1; - int maxAsc, maxDesc; + int maxAsc = 0; + int maxDesc = 0; InsetText * inset; bool changed = false; @@ -1045,15 +1119,18 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, // change so I'll try this to have a boost, but who knows ;) if ((need_update != INIT) && (the_locking_inset == tabular->GetCellInset(actcell))) { - maxAsc = the_locking_inset->ascent(bv, font); - maxDesc = the_locking_inset->descent(bv, font); + for(int i = 0; i < tabular->columns(); ++i) { + maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font), + maxAsc); + maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font), + maxDesc); + } changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font)); changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed; changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed; return changed; } for (int i = 0; i < tabular->rows(); ++i) { - maxAsc = maxDesc = 0; for (int j= 0; j < tabular->columns(); ++j) { if (tabular->IsPartOfMultiColumn(i,j)) continue; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 9a9a18195e..7ecaf13856 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -253,7 +253,8 @@ int InsetText::descent(BufferView * bv, LyXFont const &) const int InsetText::width(BufferView * bv, LyXFont const &) const { - insetWidth = TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET); + insetWidth = max(textWidth(bv->painter()), + (int)TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET)); return insetWidth; } @@ -288,8 +289,10 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, xpos = x; UpdatableInset::draw(bv, f, baseline, x, cleared); - if (!cleared && ((need_update==FULL) || (top_x!=int(x)) || - (top_baseline!=baseline))) { + // if top_x differs we have a rule down and we don't have to clear anything + if (!cleared && (top_x == int(x)) && + ((need_update==FULL) || (top_baseline!=baseline))) + { int w = insetWidth; int h = insetAscent + insetDescent; int ty = baseline - insetAscent; @@ -310,6 +313,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, return; if (top_x != int(x)) { +// printf("InsetText::draw1 -> INIT(%d)\n",insetWidth); need_update = INIT; top_x = int(x); bv->text->status = LyXText::CHANGED_IN_DRAW; @@ -346,7 +350,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, if (y_offset < 0) y_offset = y; TEXT(bv)->first = first; - if (cleared || !locked || (need_update == FULL)) { + if (cleared || !locked || (need_update==FULL) || (need_update==INIT)) { int yf = y_offset; y = 0; while ((row != 0) && (yf < ph)) { @@ -384,7 +388,10 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, } x += width(bv, f) - TEXT_TO_INSET_OFFSET; if (bv->text->status==LyXText::CHANGED_IN_DRAW) + { need_update = INIT; +// printf("InsetText::draw2 -> INIT(%d)\n",insetWidth); + } else if (need_update != INIT) need_update = NONE; } @@ -446,6 +453,8 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit) void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty) { +// if (what == INIT) +// printf("InsetText::UpdateLocal -> INIT(%d)\n",insetWidth); TEXT(bv)->FullRebreak(bv); if (need_update != INIT) { if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH) @@ -1432,6 +1441,15 @@ void InsetText::SetParagraphData(LyXParagraph *p) } +void InsetText::SetText(string const & data) +{ + clear(); + LyXFont font(LyXFont::ALL_SANE); + for(unsigned int i=0; i < data.length(); ++i) + par->InsertChar(i, data[i], font); +} + + void InsetText::SetAutoBreakRows(bool flag) { if (flag != autoBreakRows) { diff --git a/src/insets/insettext.h b/src/insets/insettext.h index d7b1e9757a..c347f37bba 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -158,6 +158,8 @@ public: /// void SetParagraphData(LyXParagraph *); /// + void SetText(string const &); + /// void SetAutoBreakRows(bool); /// void SetDrawFrame(BufferView *, DrawFrame); diff --git a/src/screen.C b/src/screen.C index 8a8f9d1f79..eb8b55d536 100644 --- a/src/screen.C +++ b/src/screen.C @@ -113,9 +113,9 @@ void LyXScreen::DrawFromTo(LyXText * text, BufferView * bv, // y1 is now the real beginning of row on the screen while (row != 0 && y < y2) { - LyXText::text_status st = text->status; + LyXText::text_status st = bv->text->status; do { - text->status = st; + bv->text->status = st; #if 0 text->GetVisibleRow(owner.owner(), y + y_offset, x_offset, row, y + text->first); @@ -123,8 +123,8 @@ void LyXScreen::DrawFromTo(LyXText * text, BufferView * bv, text->GetVisibleRow(bv, y + y_offset, x_offset, row, y + text->first); #endif - } while (text->status == LyXText::CHANGED_IN_DRAW); - text->status = st; + } while (bv->text->status == LyXText::CHANGED_IN_DRAW); + bv->text->status = st; y += row->height(); row = row->next(); } @@ -148,9 +148,9 @@ void LyXScreen::DrawOneRow(LyXText * text, BufferView * bv, Row * row, if (((y + row->height()) > 0) && ((y - row->height()) <= static_cast(owner.height()))) { // ok there is something visible - LyXText::text_status st = text->status; + LyXText::text_status st = bv->text->status; do { - text->status = st; + bv->text->status = st; #if 0 text->GetVisibleRow(owner.owner(), y, x_offset, row, y + text->first); @@ -158,8 +158,8 @@ void LyXScreen::DrawOneRow(LyXText * text, BufferView * bv, Row * row, text->GetVisibleRow(bv, y, x_offset, row, y + text->first); #endif - } while (text->status == LyXText::CHANGED_IN_DRAW); - text->status = st; + } while (bv->text->status == LyXText::CHANGED_IN_DRAW); + bv->text->status = st; } force_clear = false; } diff --git a/src/tabular.C b/src/tabular.C index 84a75cfbbf..707c9c353f 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -2548,6 +2548,12 @@ InsetText * LyXTabular::GetCellInset(int cell) const } +InsetText * LyXTabular::GetCellInset(int row, int column) const +{ + return GetCellInset(GetCellNumber(row, column)); +} + + void LyXTabular::Validate(LaTeXFeatures & features) const { if (IsLongTabular()) diff --git a/src/tabular.h b/src/tabular.h index 8e4ddce6de..6b5a9449e5 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -365,6 +365,7 @@ public: bool GetLTNewPage(int cell) const; /// InsetText * GetCellInset(int cell) const; + InsetText * GetCellInset(int row, int column) const; /// int rows() const { return rows_; } /// diff --git a/src/text.C b/src/text.C index 52307ec5c3..be6bb3b6a3 100644 --- a/src/text.C +++ b/src/text.C @@ -504,10 +504,12 @@ void LyXText::draw(BufferView * bview, Row const * row, // tmpinset->update(bview, font, false); tmpinset->draw(bview, font, offset+row->baseline(), x, cleared); +#ifdef SEEMS_TO_BE_NOT_NEEDED if (status == CHANGED_IN_DRAW) { UpdateInset(bview, tmpinset); status = CHANGED_IN_DRAW; } +#endif } ++vpos;