]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
Added using directive.
[lyx.git] / src / insets / insettext.C
index a86af9914e67dbd021292f7fcfe7a17ff7d52c23..e4e845396f758e152e556a44b30f6bec68a359f4 100644 (file)
@@ -54,6 +54,7 @@ using std::ifstream;
 using std::endl;
 using std::min;
 using std::max;
+using std::make_pair;
 
 extern unsigned char getCurrentTextClass(Buffer *);
 extern bool math_insert_greek(BufferView *, char);
@@ -111,6 +112,7 @@ void InsetText::init(InsetText const * ins)
        old_par = 0;
        last_drawn_width = -1;
        frame_is_visible = false;
+       cached_bview = 0;
 }
 
 
@@ -118,6 +120,7 @@ InsetText::~InsetText()
 {
        // delete all instances of LyXText before deleting the paragraps used
        // by it.
+       cached_bview = 0;
        for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
                delete (*cit).second;
                (*cit).second = 0;
@@ -135,6 +138,7 @@ void InsetText::clear()
 {
        // delete all instances of LyXText before deleting the paragraps used
        // by it.
+       cached_bview = 0;
        for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
                delete (*cit).second;
                (*cit).second = 0;
@@ -1498,6 +1502,7 @@ void InsetText::setParagraphData(Paragraph * p)
 {
        // delete all instances of LyXText before deleting the paragraps used
        // by it.
+       cached_bview = 0;
        for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit){
                delete (*cit).second;
                (*cit).second = 0;
@@ -1613,31 +1618,53 @@ Row * InsetText::crow(BufferView * bv) const
 LyXText * InsetText::getLyXText(BufferView const * lbv,
                                bool const recursive) const
 {
+       if (!recursive && (cached_bview == lbv))
+               return cached_text;
+       
        // Super UGLY! (Lgb)
        BufferView * bv = const_cast<BufferView *>(lbv);
        
-       if ((cache.find(bv) != cache.end()) && cache[bv]) {
-               if (recursive && the_locking_inset)
+       cached_bview = bv;
+       Cache::iterator it = cache.find(bv);
+       
+       if (it != cache.end()) {
+               lyx::Assert(it->second);
+                       
+               cached_text = it->second;
+               if (recursive && the_locking_inset) {
                        return the_locking_inset->getLyXText(bv);
-               return cache[bv];
+               }
+               return cached_text;
        }
-       LyXText * lt = new LyXText(const_cast<InsetText *>(this));
-       lt->init(bv);
-       cache[bv] = lt;
+       cached_text = new LyXText(const_cast<InsetText *>(this));
+       cached_text->init(bv);
+
+       cache.insert(make_pair(bv, cached_text));
+       
        if (the_locking_inset) {
-               lt->setCursor(bv, inset_par, inset_pos, true, inset_boundary);
-               if (recursive)
+               cached_text->setCursor(bv, inset_par, inset_pos,
+                                                          true, inset_boundary);
+               if (recursive) {
                        return the_locking_inset->getLyXText(bv);
+               }
        }
-       return lt;
+       return cached_text;
 }
 
 
 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
 {
-       if ((cache.find(bv) == cache.end()) || !cache[bv])
+       cached_bview = 0;
+
+       Cache::iterator it = cache.find(bv);
+       
+       if (it == cache.end()) {
                return;
-       delete cache[bv];
+       }
+
+       lyx::Assert(it->second);
+       
+       delete it->second;
        cache.erase(bv);
        if (recursive) {
                /// then remove all LyXText in text-insets
@@ -1656,9 +1683,13 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
        // one endless line, resize normally not necessary
        if (!force && getMaxWidth(bv, this) < 0)
                return;
-       if ((cache.find(bv) == cache.end()) || !cache[bv])
-               return;
 
+       Cache::iterator it = cache.find(bv);
+       if (it == cache.end()) {
+               return;
+       }
+       lyx::Assert(it->second);
+       
        Paragraph * lpar = 0;
        Paragraph * selstartpar = 0;
        Paragraph * selendpar = 0;
@@ -1674,7 +1705,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
 //    ProhibitInput(bv);
 
        if (locked) {
-                       LyXText * t = getLyXText(bv);
+               LyXText * t = getLyXText(bv);
                lpar = t->cursor.par();
                pos = t->cursor.pos();
                boundary = t->cursor.boundary();
@@ -1690,7 +1721,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
        deleteLyXText(bv, (the_locking_inset == 0) || force);
 
        if (lpar) {
-                       LyXText * t = getLyXText(bv);
+               LyXText * t = getLyXText(bv);
                        
                t->selection.set(true);
                /* at this point just to avoid the Delete-Empty-Paragraph