]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
don't draw invisible things...
[lyx.git] / src / BufferView_pimpl.C
index 4a11df383f117c610d2cb09c279744fddcc2fbc5..0970eac913b266447a7527744dc340182a2e11d1 100644 (file)
@@ -311,7 +311,7 @@ int BufferView::Pimpl::resizeCurrentBuffer()
        pos_type selendpos = 0;
        bool selection = false;
        bool mark_set  = false;
-
+       
        owner_->prohibitInput();
 
        owner_->message(_("Formatting document..."));
@@ -329,6 +329,7 @@ int BufferView::Pimpl::resizeCurrentBuffer()
                delete bv_->text;
                bv_->text = new LyXText(bv_);
                bv_->text->init(bv_);
+               buffer_->resizeInsets(bv_);
        } else {
                // See if we have a text in TextCache that fits
                // the new buffer_ with the correct width.
@@ -345,14 +346,16 @@ int BufferView::Pimpl::resizeCurrentBuffer()
                } else {
                        bv_->text = new LyXText(bv_);
                        bv_->text->init(bv_);
+                       //buffer_->resizeInsets(bv_);
                }
        }
+
        updateScreen();
 
        if (par) {
                bv_->text->selection.set(true);
-               /* at this point just to avoid the Delete-Empty-Paragraph
-                * Mechanism when setting the cursor */
+               // At this point just to avoid the Delete-Empty-Paragraph-
+               // Mechanism when setting the cursor.
                bv_->text->selection.mark(mark_set);
                if (selection) {
                        bv_->text->setCursor(bv_, selstartpar, selstartpos);
@@ -368,10 +371,9 @@ int BufferView::Pimpl::resizeCurrentBuffer()
                // remake the inset locking
                bv_->theLockingInset(the_locking_inset);
        }
+
        bv_->text->first_y = screen_->topCursorVisible(bv_->text);
-#if 0
-       buffer_->resizeInsets(bv_);
-#endif
+
        // this will scroll the screen such that the cursor becomes visible
        updateScrollbar();
        redraw();
@@ -997,6 +999,7 @@ void BufferView::Pimpl::workAreaExpose()
                        if (lyxerr.debugging())
                                textcache.show(lyxerr, "Expose delete all");
                        textcache.clear();
+                       buffer_->resizeInsets(bv_);
                } else if (heightChange) {
                        // Rebuild image of current screen
                        updateScreen();
@@ -1145,9 +1148,8 @@ void BufferView::Pimpl::cursorPrevious(LyXText * text)
                return;
        
        int y = text->first_y;
-       if (text->inset_owner)
-               y += bv_->text->first_y;
        Row * cursorrow = text->cursor.row();
+       
        text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
        finishUndo();
        // This is to allow jumping over large insets
@@ -1192,7 +1194,8 @@ void BufferView::Pimpl::cursorNext(LyXText * text)
 
 bool BufferView::Pimpl::available() const
 {
-       if (buffer_ && bv_->text) return true;
+       if (buffer_ && bv_->text)
+               return true;
        return false;
 }
 
@@ -1424,9 +1427,13 @@ void BufferView::Pimpl::moveCursorUpdate(bool selecting)
                lt->setSelection(bv_);
                if (lt->bv_owner)
                        toggleToggle();
+               else
+                       updateInset(lt->inset_owner, false);
+       }
+       if (lt->bv_owner) {
+               update(lt, BufferView::SELECT|BufferView::FITCUR);
+               showCursor();
        }
-       update(lt, BufferView::SELECT|BufferView::FITCUR);
-       showCursor();
        
        /* ---> Everytime the cursor is moved, show the current font state. */
        // should this too me moved out of this func?
@@ -2253,7 +2260,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        case LFUN_ENDSEL:
        {
                LyXText * lt = bv_->getLyXText();
-               
+
                update(lt, BufferView::SELECT|BufferView::FITCUR);
                lt->cursorEnd(bv_);
                finishUndo();
@@ -2349,7 +2356,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                               | BufferView::FITCUR
                               | BufferView::CHANGE);
                } else {
-                       protectedBlank(lt);
+                       specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
                }
                moveCursorUpdate(false);
        }
@@ -3255,27 +3262,6 @@ void BufferView::Pimpl::hfill()
 }
 
 
-void BufferView::Pimpl::protectedBlank(LyXText * lt)
-{
-       if (available()) {
-               hideCursor();
-               update(lt, BufferView::SELECT|BufferView::FITCUR);
-               InsetSpecialChar * new_inset =
-                       new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
-#ifdef WITH_WARNINGS
-#warning Why is this code different from specialChar() below? (JMarc)
-// the code in specialChar is a generic version of what used to exist
-// for other special chars. I did not merge this case because of the
-// call to updateInset(), but what does it do?
-#endif
-               if (!insertInset(new_inset))
-                       delete new_inset;
-               else
-                       updateInset(new_inset, true);
-       }
-}
-
-
 void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
 {
        if (available()) {
@@ -3287,6 +3273,8 @@ void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
                        new InsetSpecialChar(kind);
                if (!insertInset(new_inset))
                        delete new_inset;
+               else
+                       updateInset(new_inset, true);
        }
 }
 
@@ -3405,7 +3393,7 @@ bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
 
 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
 {
-       if (!inset)
+       if (!inset || !available())
                return;
 
        // first check for locking insets
@@ -3431,9 +3419,14 @@ void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
                }
        }
   
-       // then check the current buffer
-       if (available()) {
-               hideCursor();
+       // then check if the inset is a top_level inset (has no owner)
+       // if yes do the update as always otherwise we have to update the
+       // toplevel inset where this inset is inside
+       Inset * tl_inset = inset;
+       while(tl_inset->owner())
+               tl_inset = tl_inset->owner();
+       hideCursor();
+       if (tl_inset == inset) {
                update(bv_->text, BufferView::UPDATE);
                if (bv_->text->updateInset(bv_, inset)) {
                        if (mark_dirty) {
@@ -3446,6 +3439,13 @@ void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
                        }
                        return;
                }
+       } else if (static_cast<UpdatableInset *>(tl_inset)
+                          ->updateInsetInInset(bv_, inset))
+       {
+                       if (bv_->text->updateInset(bv_,  tl_inset)) {
+                               update();
+                               updateScrollbar();
+                       }
        }
 }