]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcollapsable.C
The markDirty() and fitCursor() changes
[lyx.git] / src / insets / insetcollapsable.C
index d646ce22951bad1f94180c1b9da5ae61d48fb6bb..1be8c4398c94c0076bca0ad11afe144cd3010ec5 100644 (file)
 #include "lyxtext.h"
 #include "WordLangTuple.h"
 #include "funcrequest.h"
+#include "buffer.h"
 
 #include "frontends/font_metrics.h"
 #include "frontends/Painter.h"
+#include "frontends/LyXView.h"
 
+#include "support/LAssert.h"
 #include "support/LOstream.h"
 #include "support/lstrings.h"
 
@@ -181,11 +184,14 @@ void InsetCollapsable::draw_collapsed(Painter & pain,
 
 
 void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
-                           int baseline, float & x, bool cleared) const
+                           int baseline, float & x) const
 {
+       lyx::Assert(bv);
+       cache(bv);
+
        if (need_update != NONE) {
                const_cast<InsetText *>(&inset)->update(bv, f, true);
-               bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
+               bv->text->postChangedInDraw();
                need_update = NONE;
                return;
        }
@@ -209,18 +215,6 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
        if (!owner())
                x += static_cast<float>(scroll());
 
-       if (!cleared && (inset.need_update == InsetText::FULL ||
-                        inset.need_update == InsetText::INIT ||
-                        top_x != int(x) ||
-                        top_baseline != baseline))
-       {
-               // we don't need anymore to clear here we just have to tell
-               // the underlying LyXText that it should do the RowClear!
-               inset.setUpdateStatus(bv, InsetText::FULL);
-               bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
-               return;
-       }
-
        top_x = int(x);
        topx_set = true;
        top_baseline = baseline;
@@ -228,9 +222,7 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
        int const bl = baseline - ascent(bv, f) + ascent_collapsed();
 
        draw_collapsed(pain, bl, old_x);
-       inset.draw(bv, f,
-                          bl + descent_collapsed() + inset.ascent(bv, f),
-                          x, cleared);
+       inset.draw(bv, f, bl + descent_collapsed() + inset.ascent(bv, f), x);
        if (x < (top_x + button_length + TEXT_TO_INSET_OFFSET))
                x = top_x + button_length + TEXT_TO_INSET_OFFSET;
 }
@@ -254,7 +246,8 @@ void InsetCollapsable::edit(BufferView * bv, int xp, int yp,
                first_after_edit = true;
                if (!bv->lockInset(this))
                        return;
-               bv->updateInset(this, false);
+               bv->updateInset(this);
+               bv->buffer()->markDirty();
                inset.edit(bv);
        } else {
                if (!bv->lockInset(this))
@@ -282,7 +275,8 @@ void InsetCollapsable::edit(BufferView * bv, bool front)
                if (!bv->lockInset(this))
                        return;
                inset.setUpdateStatus(bv, InsetText::FULL);
-               bv->updateInset(this, false);
+               bv->updateInset(this);
+               bv->buffer()->markDirty();
                inset.edit(bv, front);
                first_after_edit = true;
        } else {
@@ -316,7 +310,7 @@ void InsetCollapsable::insetUnlock(BufferView * bv)
        inset.insetUnlock(bv);
        if (scroll())
                scroll(bv, 0.0F);
-       bv->updateInset(this, false);
+       bv->updateInset(this);
 }
 
 
@@ -346,11 +340,13 @@ bool InsetCollapsable::lfunMouseRelease(FuncRequest const & cmd)
 // should not be called on inset open!
 //                     inset.insetButtonRelease(bv, 0, 0, button);
                        inset.setUpdateStatus(bv, InsetText::FULL);
-                       bv->updateInset(this, false);
+                       bv->updateInset(this);
+                       bv->buffer()->markDirty();
                } else {
                        collapsed_ = true;
                        bv->unlockInset(this);
-                       bv->updateInset(this, false);
+                       bv->updateInset(this);
+                       bv->buffer()->markDirty();
                }
        } else if (!collapsed_ && (cmd.y > button_bottom_y)) {
                LyXFont font(LyXFont::ALL_SANE);
@@ -558,12 +554,6 @@ void InsetCollapsable::setFont(BufferView * bv, LyXFont const & font,
 }
 
 
-bool InsetCollapsable::doClearArea() const
-{
-       return inset.doClearArea();
-}
-
-
 LyXText * InsetCollapsable::getLyXText(BufferView const * bv,
                                       bool const recursive) const
 {
@@ -608,13 +598,6 @@ int InsetCollapsable::scroll(bool recursive) const
 }
 
 
-Paragraph * InsetCollapsable::getParFromID(int id) const
-{
-       lyxerr[Debug::INFO] << "Looking for paragraph " << id << endl;
-       return inset.getParFromID(id);
-}
-
-
 Paragraph * InsetCollapsable::firstParagraph() const
 {
        return inset.firstParagraph();
@@ -646,7 +629,7 @@ void InsetCollapsable::open(BufferView * bv)
        if (!collapsed_) return;
 
        collapsed_ = false;
-       bv->updateInset(this, false);
+       bv->updateInset(this);
 }
 
 
@@ -656,7 +639,7 @@ void InsetCollapsable::close(BufferView * bv) const
                return;
 
        collapsed_ = true;
-       bv->updateInset(const_cast<InsetCollapsable *>(this), false);
+       bv->updateInset(const_cast<InsetCollapsable *>(this));
 }
 
 
@@ -671,11 +654,11 @@ void InsetCollapsable::markErased()
        inset.markErased();
 }
 
+
 bool InsetCollapsable::nextChange(BufferView * bv, lyx::pos_type & length)
 {
        bool found = inset.nextChange(bv, length);
+
        if (first_after_edit && !found)
                close(bv);
        else if (!found)
@@ -683,7 +666,7 @@ bool InsetCollapsable::nextChange(BufferView * bv, lyx::pos_type & length)
        return found;
 }
 
+
 bool InsetCollapsable::searchForward(BufferView * bv, string const & str,
                                     bool cs, bool mw)
 {
@@ -723,3 +706,15 @@ void InsetCollapsable::addPreview(grfx::PreviewLoader & loader) const
 {
        inset.addPreview(loader);
 }
+
+
+void InsetCollapsable::cache(BufferView * bv) const
+{
+       view_ = bv->owner()->view();
+}
+
+
+BufferView * InsetCollapsable::view() const
+{
+       return view_.lock().get();
+}