From 9d2abd45056c0e99cdb3267d2e666a36b7032406 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Tue, 4 Dec 2001 16:10:19 +0000 Subject: [PATCH] More fixes. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3143 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 ++++ src/insets/ChangeLog | 12 ++++++++ src/insets/insetert.C | 34 ++++++++++++++++++++-- src/insets/insetert.h | 4 +++ src/insets/insettabular.C | 6 ++++ src/insets/insettext.C | 43 +++++++++++++++++++--------- src/insets/insettext.h | 2 +- src/tabular.C | 20 +++++++++---- src/tabular.h | 5 +++- src/text.C | 59 ++++++++++++++++++--------------------- src/text2.C | 2 +- src/undo_funcs.C | 2 ++ 12 files changed, 138 insertions(+), 56 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 03bc2152e6..ca8ed313da 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2001-12-04 Juergen Vigna + + * undo_funcs.C (textHandleUndo): added a call to inset->update() so + that we force an update of the inset and it's owners if neccessary. + 2001-12-03 Juergen Vigna * text.C (rowLast): simplified code diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index b0cb4a1c50..9d6bd983fa 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,15 @@ +2001-12-04 Juergen Vigna + + * insetert.C (edit): handle Inlined status. + + * insettext.C (insertInset): trying John's fix for the trailing cursor + + * insetert.C (insetButtonPress): added to handle inlined status + (insetMotionNotify): ditto. + + * insettext.C (clearInset): changed Painter & in BufferView * param, + to be able to call ascent,descent methods. + 2001-12-03 Juergen Vigna * insettext.C (updateInsetInInset): use lt variable to forbid diff --git a/src/insets/insetert.C b/src/insets/insetert.C index ce143c7ca4..e964ea2b9d 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -257,8 +257,14 @@ void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button) { if (button == 3) return; - - InsetCollapsable::edit(bv, x, y, button); + + if (status_ == Inlined) { + if (!bv->lockInset(this)) + return; + inset.edit(bv, x, y, button); + } else { + InsetCollapsable::edit(bv, x, y, button); + } updateStatus(0); set_latex_font(bv); } @@ -280,6 +286,19 @@ void InsetERT::edit(BufferView * bv, bool front) } + + +void InsetERT::insetButtonPress(BufferView * bv, + int x, int y, int button) +{ + if (status_ == Inlined) { + inset.insetButtonPress(bv, x, y, button); + } else { + InsetCollapsable::insetButtonPress(bv, x, y, button); + } +} + + void InsetERT::insetButtonRelease(BufferView * bv, int x, int y, int button) { if (button == 3) { @@ -306,6 +325,17 @@ void InsetERT::insetButtonRelease(BufferView * bv, int x, int y, int button) } +void InsetERT::insetMotionNotify(BufferView * bv, + int x, int y, int state) +{ + if (status_ == Inlined) { + inset.insetMotionNotify(bv, x, y, state); + } else { + InsetCollapsable::insetMotionNotify(bv, x, y, state); + } +} + + int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/, bool /*free_spc*/) const { diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 4c63335f8b..78b89be521 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -71,8 +71,12 @@ public: /// SigC::Signal0 hideDialog; /// + void insetButtonPress(BufferView *, int x, int y, int button); + /// void insetButtonRelease(BufferView * bv, int x, int y, int button); /// + void insetMotionNotify(BufferView *, int x, int y, int state); + /// int latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const; /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 02ba393353..f5d9da9878 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -587,6 +587,10 @@ void InsetTabular::insetUnlock(BufferView * bv) void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty) const { + if (what == INIT) { + LyXFont font; + calculate_dimensions_of_cells(bv, font, true); + } if (need_update < what) // only set this if it has greater update need_update = what; if ((what == INIT) && hasSelection()) @@ -1244,6 +1248,8 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed; changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed; } + if (changed) + tabular->reinit(); return changed; } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index e3b43f0f1a..0a120b4b51 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -376,7 +376,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, // repaint the background if needed if (cleared && backgroundColor() != LColor::background) { top_x = int(x); - clearInset(pain, baseline, cleared); + clearInset(bv, baseline, cleared); top_x = old_x; } @@ -400,7 +400,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, if (!cleared && (top_x == int(x)) && ((need_update&(INIT|FULL)) || (top_baseline!=baseline) || (last_drawn_width!=insetWidth))) { - clearInset(pain, baseline, cleared); + clearInset(bv, baseline, cleared); } top_x = int(x); @@ -419,9 +419,9 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, last_width = width(bv, f); last_height = ascent(bv, f) + descent(bv, f); - if (cleared || (last_drawn_width != insetWidth)) { + if (last_drawn_width != insetWidth) { if (!cleared) - clearInset(pain, baseline, cleared); + clearInset(bv, baseline, cleared); need_update |= FULL; last_drawn_width = insetWidth; } @@ -1004,14 +1004,22 @@ void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state) y - inset_y,state); return; } - LyXText * t = getLyXText(bv); + bool clear = false; + if (!lt) { + lt = getLyXText(bv); + clear = true; + } hideInsetCursor(bv); - t->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent); - t->setSelection(bv); - if (t->toggle_cursor.par() != t->toggle_end_cursor.par() || - t->toggle_cursor.pos() != t->toggle_end_cursor.pos()) + lt->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent); + lt->setSelection(bv); + if (lt->toggle_cursor.par() != lt->toggle_end_cursor.par() || + lt->toggle_cursor.pos() != lt->toggle_end_cursor.pos()) + { updateLocal(bv, SELECTION, false); + } showInsetCursor(bv); + if (clear) + lt = 0; } @@ -1782,7 +1790,7 @@ bool InsetText::insertInset(BufferView * bv, Inset * inset) #endif bv->fitCursor(); updateLocal(bv, CURSOR_PAR|CURSOR, true); - showInsetCursor(bv); +// showInsetCursor(bv); if (clear) lt = 0; return true; @@ -2282,10 +2290,12 @@ void InsetText::clearSelection(BufferView * bv) } -void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const +void InsetText::clearInset(BufferView * bv, int baseline, bool & cleared) const { + LyXFont dummy; + Painter & pain = bv->painter(); int w = insetWidth; - int h = insetAscent + insetDescent; + int h = ascent(bv, dummy) + descent(bv, dummy); int ty = baseline - insetAscent; if (ty < 0) { @@ -2318,7 +2328,6 @@ Paragraph * InsetText::getParFromID(int id) const #else Paragraph * tmp = par; while (tmp) { - int tmp_id = tmp->id(); if (tmp->id() == id) { return tmp; } @@ -2365,6 +2374,14 @@ Paragraph * InsetText::paragraph() const void InsetText::paragraph(Paragraph * p) { + // first we have to delete the old contents otherwise we'll have a + // memory leak! + the_locking_inset = 0; + while (par) { + Paragraph * tmp = par->next(); + delete par; + par = tmp; + } par = p; // set ourself as owner for all the paragraphs inserted! Paragraph * np = par; diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 0938e43e87..ab981c6a63 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -320,7 +320,7 @@ private: /// void clearFrame(Painter &, bool cleared) const; /// - void clearInset(Painter &, int baseline, bool & cleared) const; + void clearInset(BufferView *, int baseline, bool & cleared) const; /// void saveLyXTextState(LyXText *) const; void restoreLyXTextState(BufferView *, LyXText *) const; diff --git a/src/tabular.C b/src/tabular.C index 5213651290..60ee577dbe 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -341,12 +341,20 @@ void LyXTabular::DeleteColumn(int column) } -void LyXTabular::Reinit() -{ - for (int i = 0; i < rows_; ++i) { - for (int j = 0; j < columns_; ++j) { - cell_info[i][j].width_of_cell = 0; - cell_info[i][j].inset.setOwner(owner_); +void LyXTabular::reinit() +{ + Reinit(false); +} + + +void LyXTabular::Reinit(bool reset_widths) +{ + if (reset_widths) { + for (int i = 0; i < rows_; ++i) { + for (int j = 0; j < columns_; ++j) { + cell_info[i][j].width_of_cell = 0; + cell_info[i][j].inset.setOwner(owner_); + } } } diff --git a/src/tabular.h b/src/tabular.h index d48e8eaa84..e93aa9f7e5 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -394,6 +394,9 @@ public: /// std::vector const getLabelList() const; /// + /// recalculate the widths/heights only! + void reinit(); + /// mutable int cur_cell; private: /// @@ -518,7 +521,7 @@ private: /// void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0); /// - void Reinit(); + void Reinit(bool reset_widths = true); /// void set_row_column_number_info(bool oldformat = false); /// Returns true if a complete update is necessary, otherwise false diff --git a/src/text.C b/src/text.C index d4ccf901e0..91cd223279 100644 --- a/src/text.C +++ b/src/text.C @@ -181,7 +181,7 @@ unsigned char LyXText::transformChar(unsigned char c, Paragraph * par, // Lgb int LyXText::singleWidth(BufferView * bview, Paragraph * par, - pos_type pos) const + pos_type pos) const { char const c = par->getChar(pos); return singleWidth(bview, par, pos, c); @@ -215,7 +215,10 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par, } else if (c == Paragraph::META_INSET) { Inset * tmpinset = par->getInset(pos); if (tmpinset) { -#if 0 // seems not to be needed, but ... +#if 1 + // this IS needed otherwise on initialitation we don't get the fill + // of the row right (ONLY on initialization if we read a file!) + // should be changed! (Jug 20011204) tmpinset->update(bview, font); #endif return tmpinset->width(bview, font); @@ -1039,13 +1042,6 @@ int LyXText::fill(BufferView * bview, Row * row, int paper_width) const } int const fill = paper_width - w - rightMargin(bview->buffer(), row); -#ifdef WITH_WARNINGS -#warning Please fix me (Jug!) -#endif -#if 0 - if (fill < 0) - return 0; -#endif return fill; } @@ -1515,35 +1511,34 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const * start at the implicit given position */ void LyXText::appendParagraph(BufferView * bview, Row * row) const { - bool not_ready = true; + bool not_ready = true; - // The last character position of a paragraph is an invariant so we can - // safely get it here. (Asger) - pos_type const lastposition = row->par()->size(); - do { - // Get the next breakpoint - pos_type z = nextBreakPoint(bview, row, workWidth(bview)); + // The last character position of a paragraph is an invariant so we can + // safely get it here. (Asger) + pos_type const lastposition = row->par()->size(); + do { + // Get the next breakpoint + pos_type z = nextBreakPoint(bview, row, workWidth(bview)); - Row * tmprow = row; + Row * tmprow = row; - // Insert the new row - if (z < lastposition) { - ++z; - insertRow(row, row->par(), z); - row = row->next(); + // Insert the new row + if (z < lastposition) { + ++z; + insertRow(row, row->par(), z); + row = row->next(); - row->height(0); - } else - not_ready = false; + row->height(0); + } else + not_ready = false; - // Set the dimensions of the row -#ifdef WITH_WARNINGS -#warning Something is rotten here! (Jug) -#endif - tmprow->fill(fill(bview, tmprow, workWidth(bview))); - setHeightOfRow(bview, tmprow); + // Set the dimensions of the row + // fixed fill setting now by calling inset->update() in + // SingleWidth when needed! + tmprow->fill(fill(bview, tmprow, workWidth(bview))); + setHeightOfRow(bview, tmprow); - } while (not_ready); + } while (not_ready); } diff --git a/src/text2.C b/src/text2.C index 0c092dff9a..3b2df2e203 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1054,7 +1054,7 @@ void LyXText::clearSelection() const { selection.set(false); selection.mark(false); - selection.end = selection.start = selection.cursor = cursor; + last_sel_cursor = selection.end = selection.start = selection.cursor = cursor; } diff --git a/src/undo_funcs.C b/src/undo_funcs.C index e010d5773d..69ad13d275 100644 --- a/src/undo_funcs.C +++ b/src/undo_funcs.C @@ -168,6 +168,8 @@ bool textHandleUndo(BufferView * bv, Undo * undo) it->getLyXText(bv)->setCursorIntern(bv, tmppar, undo->cursor_pos); it->getLyXText(bv)->updateCounters(bv, it->getLyXText(bv)->cursor.row()); } + LyXFont font; + it->update(bv, font, false); #ifdef THIS_DOES_NOT_WORK // we need this anyway as also if the undo was inside an inset // we have to redo the paragraph breaking -- 2.39.2