]> git.lyx.org Git - features.git/commitdiff
add parOwner to Inset, optimize LyXText::workWidth, fix memory corruption with lots...
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 12 Dec 2001 09:56:03 +0000 (09:56 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 12 Dec 2001 09:56:03 +0000 (09:56 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3195 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/ChangeLog
src/frontends/xforms/ChangeLog
src/frontends/xforms/Menubar_pimpl.C
src/frontends/xforms/xforms_helpers.C
src/frontends/xforms/xforms_helpers.h
src/insets/ChangeLog
src/insets/inset.C
src/insets/inset.h
src/lyxtext.h
src/paragraph.C
src/paragraph.h
src/paragraph_pimpl.C
src/text.C
src/undo_funcs.C

index dc8a2b76df7d37c7aee4f42112314f98070a66b9..6f2655e34ff689329fc2d6cb3ec8afbd6d269d4a 100644 (file)
@@ -1,3 +1,17 @@
+2001-12-12  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * 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  <lasgouttes@freesurf.fr>
 
        * tabular-old.C (getTokenValue): 
index 329b608f767cb54f69193660f737aad547ed79ab..b21e34d7e5e296e3e6e17f8ca37bc60e16989d7d 100644 (file)
@@ -1,5 +1,13 @@
+2001-12-11  Ben Stanley <bds02@uow.edu.au>
+
+       * 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  <lasgouttes@freesurf.fr>
 
+       * xforms_helpers.C: include lyxlength.h here
+       * xforms_helpers.h: ... but not here
+
        * FormTabular.C: use LyXLength instead of string wherever
        necessary; whitespace changes.
 
index 53ab5c71252b94e8b6bba01f14d7b7d76d34d64b..53de1a19765c169fb559a434ddd6b1c0b2a96ba1 100644 (file)
@@ -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);
        }
        
        
index 07ecdadea56559ba83b9445643fd736849e49d4a..fed3deae019b4f3a945aa8330e945c7fd9c73017 100644 (file)
@@ -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;
index ad3133a9ea3856148ab1c5386681501f8e05ca65..0e6b6050113fb3fcf3e92e057f718eca1f971e6c 100644 (file)
 #include FORMS_H_LOCATION
  
 #include "Color.h"
-#include "support/lstrings.h"
-#include "lyxlength.h"
+#include "LString.h"
  
 #include <vector>
 
+class LyXLength;
+
 /// Extract shortcut from <ident>|<shortcut> 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<string> const getVectorFromChoice(FL_OBJECT *);
index 5f59adb5f7faf68f6ec4084baa72f1289a644b13..231682d54fafa5fae3803cd3b0999b7c97cae0e5 100644 (file)
@@ -1,3 +1,8 @@
+2001-12-11  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * inset.h: add par_owner_ member variable and parOwner
+       setter/accessor. 
+
 2001-12-10  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
 
        * insettabular.C (everywhere): adapt because widths are now real
index 90c7d74e2dbbe96c2904041858b0fa47ed6e89b3..39e9a31685589d6d0950f72b174323c5437f5493 100644 (file)
@@ -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)
 {}
 
 
index 59e2d08c6ce1b35faf82a6e40d1f1d94a43d7247..a3b98f022ddbcd9fa345826eeabf196397b2cef4 100644 (file)
@@ -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_;
        ///
index 26c92b752bc4e841bb709f062ce8f6e7e5f96506..8c6114ea6241f02b5b2536f47f266d30b3df5723 100644 (file)
@@ -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;
 
index 94662b1424b4f10a2372d4af80c0b68f4c31e026..61d2048be7ffba51d0f680940f991fac8dbe8cc7 100644 (file)
@@ -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
index a12c269dfa7c7bc152ab4b004ead9e4e9f5770fe..1e2563125cdf49ceb9617ea7df7c8c87156be041 100644 (file)
@@ -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);
        ///
index e3c85580603810e1917afc3d52eff0e01c76f6d8..be57e47838a49e86e0db83a8fe6ac00c0443795d 100644 (file)
@@ -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)
index 059ed2f8b04aedbc92cc58b0477081694ebb5e15..dfe9c260aaf730571a4f3ae0679779336b1f28cb 100644 (file)
@@ -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;
-
-       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;
+       pos_type pos = -1;
+
+       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);
        }
index 69ad13d27554771960613bdbb683600acdcb5ed6..85ad6a1c581ee1f25cd548a7779928da776bd544 100644 (file)
@@ -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);