From b00e1315fe4da81da67f63d70e455cda167afab9 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 12 Dec 2001 09:56:03 +0000 Subject: [PATCH] add parOwner to Inset, optimize LyXText::workWidth, fix memory corruption with lots of floats (Ben) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3195 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 14 ++++++++++++++ src/frontends/xforms/ChangeLog | 8 ++++++++ src/frontends/xforms/Menubar_pimpl.C | 17 ++++++++++++++--- src/frontends/xforms/xforms_helpers.C | 1 + src/frontends/xforms/xforms_helpers.h | 7 ++++--- src/insets/ChangeLog | 5 +++++ src/insets/inset.C | 3 ++- src/insets/inset.h | 6 ++++++ src/lyxtext.h | 2 +- src/paragraph.C | 8 ++++++-- src/paragraph.h | 2 +- src/paragraph_pimpl.C | 1 + src/text.C | 25 +++++++++++++++++-------- src/undo_funcs.C | 15 +++++++++------ 14 files changed, 89 insertions(+), 25 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index dc8a2b76df..6f2655e34f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2001-12-12 Jean-Marc Lasgouttes + + * text.C (workWidth): use Inset::parOwner to find out where the + inset has been inserted. This is a huge performance gain for large + documents with lots of insets. If Inset::parOwner is not set, fall + back on the brute force method + + * paragraph_pimpl.C (insertInset): + * paragraph.C (Paragraph): + (cutIntoMinibuffer): set parOwner of insets when + inserting/removing them + + * lyxtext.h: add short comment on deleteEmptyParagraphMechanism + 2001-12-10 Jean-Marc Lasgouttes * tabular-old.C (getTokenValue): diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 329b608f76..b21e34d7e5 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,5 +1,13 @@ +2001-12-11 Ben Stanley + + * Menubar_pimpl.C: Fixed a crashing bug when document has more + than 80 floats and using xforms 0.88 + 2001-12-11 Jean-Marc Lasgouttes + * xforms_helpers.C: include lyxlength.h here + * xforms_helpers.h: ... but not here + * FormTabular.C: use LyXLength instead of string wherever necessary; whitespace changes. diff --git a/src/frontends/xforms/Menubar_pimpl.C b/src/frontends/xforms/Menubar_pimpl.C index 53ab5c7125..53de1a1976 100644 --- a/src/frontends/xforms/Menubar_pimpl.C +++ b/src/frontends/xforms/Menubar_pimpl.C @@ -337,10 +337,21 @@ void Menubar::Pimpl::add_toc(int menu, string const & extra_label, if (cit->first == "TOC") continue; // All the rest is for floats - int menu2 = get_new_submenu(smn, win); + int menu_first_sub = get_new_submenu(smn, win); + int menu_current = menu_first_sub; Buffer::SingleList::const_iterator ccit = cit->second.begin(); Buffer::SingleList::const_iterator eend = cit->second.end(); + size_type count = 0; for (; ccit != eend; ++ccit) { + ++count; + if (count > max_number_of_items) { + int menu_tmp = get_new_submenu(smn, win); + string label = _("More"); + label += "...%m"; + fl_addtopup(menu_current, label.c_str(), menu_tmp); + count = 1; + menu_current = menu_tmp; + } int const action = lyxaction .getPseudoAction(LFUN_GOTO_PARAGRAPH, @@ -348,10 +359,10 @@ void Menubar::Pimpl::add_toc(int menu, string const & extra_label, string label = fixlabel(ccit->str); label = limit_string_length(label); label += "%x" + tostr(action + action_offset); - fl_addtopup(menu2, label.c_str()); + fl_addtopup(menu_current, label.c_str()); } string const m = floatList[cit->first]->second.name() + "%m"; - fl_addtopup(menu, m.c_str(), menu2); + fl_addtopup(menu, m.c_str(), menu_first_sub); } diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index 07ecdadea5..fed3deae01 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -19,6 +19,7 @@ #include "support/lstrings.h" // frontStrip, strip #include "gettext.h" #include "support/LAssert.h" +#include "lyxlength.h" using std::ofstream; using std::pair; diff --git a/src/frontends/xforms/xforms_helpers.h b/src/frontends/xforms/xforms_helpers.h index ad3133a9ea..0e6b605011 100644 --- a/src/frontends/xforms/xforms_helpers.h +++ b/src/frontends/xforms/xforms_helpers.h @@ -12,11 +12,12 @@ #include FORMS_H_LOCATION #include "Color.h" -#include "support/lstrings.h" -#include "lyxlength.h" +#include "LString.h" #include +class LyXLength; + /// Extract shortcut from | string char const * flyx_shortcut_extract(char const * sc); /// Shortcut for flyx_shortcut_extract @@ -32,7 +33,7 @@ void setEnabled(FL_OBJECT *, bool enable); /// Take a string and add breaks so that it fits into a desired label width, w string formatted(string const &label, int w, - int=FL_NORMAL_SIZE, int=FL_NORMAL_STYLE); + int = FL_NORMAL_SIZE, int = FL_NORMAL_STYLE); /// Given an fl_choice, create a vector of its entries std::vector const getVectorFromChoice(FL_OBJECT *); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 5f59adb5f7..231682d54f 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2001-12-11 Jean-Marc Lasgouttes + + * inset.h: add par_owner_ member variable and parOwner + setter/accessor. + 2001-12-10 Jean-Marc Lasgouttes * insettabular.C (everywhere): adapt because widths are now real diff --git a/src/insets/inset.C b/src/insets/inset.C index 90c7d74e2d..39e9a31685 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -35,7 +35,8 @@ unsigned int Inset::inset_id = 0; Inset::Inset() : top_x(0), topx_set(false), top_baseline(0), scx(0), - id_(inset_id++), owner_(0), background_color_(LColor::inherit) + id_(inset_id++), owner_(0), par_owner_(0), + background_color_(LColor::inherit) {} diff --git a/src/insets/inset.h b/src/insets/inset.h index 59e2d08c6c..a3b98f022d 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -226,6 +226,10 @@ public: /// Inset * owner() const { return owner_; } /// + void parOwner(Paragraph * par) { par_owner_ = par; } + /// + Paragraph * parOwner() const {return par_owner_; } + /// void setBackgroundColor(LColor::color); /// LColor::color backgroundColor() const; @@ -318,6 +322,8 @@ protected: private: /// Inset * owner_; + /// the paragraph in which this inset has been inserted + Paragraph * par_owner_; /// string name_; /// diff --git a/src/lyxtext.h b/src/lyxtext.h index 26c92b752b..8c6114ea62 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -612,7 +612,7 @@ private: LyXCursor & cur, LyXCursor const & where) const; - /// + /// delete double space or empty paragraphs around old_cursor void deleteEmptyParagraphMechanism(BufferView *, LyXCursor const & old_cursor) const; diff --git a/src/paragraph.C b/src/paragraph.C index 94662b1424..61d2048be7 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -89,7 +89,7 @@ Paragraph::Paragraph() } -// This construktor inserts the new paragraph in a list. +// This constructor inserts the new paragraph in a list. Paragraph::Paragraph(Paragraph * par) : layout(0), pimpl_(new Paragraph::Pimpl(this)) { @@ -140,6 +140,8 @@ Paragraph::Paragraph(Paragraph const & lp, bool same_ids) it != insetlist.end(); ++it) { it->inset = it->inset->clone(*current_view->buffer(), same_ids); + // tell the new inset who is the boss now + it->inset->parOwner(this); } } @@ -438,6 +440,8 @@ void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos) search_elem, Pimpl::matchIT()); if (it != insetlist.end() && it->pos == pos) it->inset = 0; + // the inset is not in a paragraph anymore + minibuffer_inset->parOwner(0); } else { minibuffer_inset = 0; minibuffer_char = ' '; @@ -1193,7 +1197,7 @@ int Paragraph::autoDeleteInsets() while (index < insetlist.size()) { if (insetlist[index].inset && insetlist[index].inset->autoDelete()) { erase(insetlist[index].pos); - // Erase() calls to insetlist.erase(&insetlist[index]) + // erase() calls to insetlist.erase(&insetlist[index]) // so index shouldn't be increased. ++count; } else diff --git a/src/paragraph.h b/src/paragraph.h index a12c269dfa..1e2563125c 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -258,7 +258,7 @@ public: /// Returns the height of the highest font in range LyXFont::FONT_SIZE highestFontInRange(lyx::pos_type startpos, lyx::pos_type endpos, - LyXFont::FONT_SIZE const def_size) const; + LyXFont::FONT_SIZE const def_size) const; /// void insertChar(lyx::pos_type pos, value_type c); /// diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index e3c8558060..be57e47838 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -150,6 +150,7 @@ void Paragraph::Pimpl::insertInset(pos_type pos, "there is an inset in position: " << pos << std::endl; } else { owner_->insetlist.insert(it, InsetTable(pos, inset)); + inset->parOwner(owner_); } if (inset_owner) diff --git a/src/text.C b/src/text.C index 059ed2f8b0..dfe9c260aa 100644 --- a/src/text.C +++ b/src/text.C @@ -69,17 +69,26 @@ int LyXText::workWidth(BufferView * bview) const int LyXText::workWidth(BufferView * bview, Inset * inset) const { Paragraph * par = 0; - pos_type pos = 0; + pos_type pos = -1; - Buffer::inset_iterator it = bview->buffer()->inset_iterator_begin(); - Buffer::inset_iterator end = bview->buffer()->inset_iterator_end(); - for ( ; it != end; ++it) { - if (*it == inset) { - par = it.getPar(); - pos = it.getPos(); - break; + par = inset->parOwner(); + if (par) + pos = par->getPositionOfInset(inset); + + if (!par || pos == -1) { + lyxerr << "LyXText::workWidth: something is wrong," + " fall back to the brute force method" << endl; + Buffer::inset_iterator it = bview->buffer()->inset_iterator_begin(); + Buffer::inset_iterator end = bview->buffer()->inset_iterator_end(); + for ( ; it != end; ++it) { + if (*it == inset) { + par = it.getPar(); + pos = it.getPos(); + break; + } } } + if (!par) { return workWidth(bview); } diff --git a/src/undo_funcs.C b/src/undo_funcs.C index 69ad13d275..85ad6a1c58 100644 --- a/src/undo_funcs.C +++ b/src/undo_funcs.C @@ -39,7 +39,7 @@ bool textUndo(BufferView * bv) if (first) { bv->buffer()->redostack.push( createUndo(bv, undo->kind, first, - bv->buffer()->getParFromID(undo->number_of_behind_par))); + bv->buffer()->getParFromID(undo->number_of_behind_par))); } } } @@ -119,8 +119,10 @@ bool textHandleUndo(BufferView * bv, Undo * undo) while (tmppar5 && tmppar5 != behind) { tmppar = tmppar5; tmppar5 = tmppar5->next(); - // a memory optimization for edit: Only layout information - // is stored in the undo. So restore the text informations. + // a memory optimization for edit: + // Only layout information + // is stored in the undo. So restore + // the text informations. if (undo->kind == Undo::EDIT) { tmppar2->setContentsFromPar(tmppar); tmppar->clearContents(); @@ -171,10 +173,11 @@ bool textHandleUndo(BufferView * bv, Undo * undo) 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 + // we need this anyway as also if the undo was + // inside an inset we have to redo the + // paragraph breaking bv->text->redoParagraphs(bv, bv->text->cursor, - bv->text->cursor.par()); + bv->text->cursor.par()); #endif } else { bv->text->redoParagraphs(bv, bv->text->cursor, endpar);