]> git.lyx.org Git - features.git/commitdiff
Fix bug 3427:
authorAbdelrazak Younes <younes@lyx.org>
Wed, 22 Aug 2007 14:14:52 +0000 (14:14 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 22 Aug 2007 14:14:52 +0000 (14:14 +0000)
http://bugzilla.lyx.org/show_bug.cgi?id=3427

The problem was that offset_ref_ was calculated based on an empty metrics. The solution is delay the calculation up until the next metrics update.

* BufferView:
- center(): now just set the anchor_ref and program a new screen recentering.
- updateOffsetRef(): update the offset_ref_

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19721 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/BufferView.h

index 5d41d1b1624e58fbd7363754a000bd9532abd5bc..40ee79c330c0b2ffcb90a831c5bb9bd175789e9f 100644 (file)
@@ -126,7 +126,7 @@ BufferView::BufferView(Buffer & buf)
        : width_(0), height_(0), buffer_(buf), wh_(0),
          cursor_(*this),
          multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0),
-         intl_(new Intl), last_inset_(0)
+         need_centering_(false), intl_(new Intl), last_inset_(0)
 {
        xsel_cache_.set = false;
        intl_->initKeyMapper(lyxrc.use_kbmap);
@@ -478,16 +478,37 @@ int BufferView::workWidth() const
 }
 
 
-void BufferView::center()
+void BufferView::updateOffsetRef()
 {
+       if (!need_centering_)
+               return;
+
+       if (height_ == 0)
+               return;
+
        CursorSlice & bot = cursor_.bottom();
        TextMetrics & tm = text_metrics_[bot.text()];
        pit_type const pit = bot.pit();
-       tm.redoParagraph(pit);
        ParagraphMetrics const & pm = tm.parMetrics(pit);
        anchor_ref_ = pit;
-       offset_ref_ = bv_funcs::coordOffset(*this, cursor_, cursor_.boundary()).y_
-               + pm.ascent() - height_ / 2;
+       //DocIterator dit;
+       //dit.push_back(bot);
+       //dit.pos() = 0;
+
+       Point p = bv_funcs::coordOffset(*this, cursor_, cursor_.boundary());
+       offset_ref_ = p.y_ + pm.ascent() - height_ / 2;
+
+       lyxerr << "p.y_ " << p.y_ << "  pm.ascent() " << pm.ascent() << "  h/2 " << height_/2
+               << "  offset_ref_ " << offset_ref_ << endl;
+
+       need_centering_ = false;
+}
+
+
+void BufferView::center()
+{
+       anchor_ref_ = cursor_.bottom().pit();
+       need_centering_ = true;
 }
 
 
@@ -1350,6 +1371,8 @@ void BufferView::updateMetrics(bool singlepar)
        if (!singlepar)
                tm.redoParagraph(pit);
 
+       updateOffsetRef();
+
        int y0 = tm.parMetrics(pit).ascent() - offset_ref_;
 
        // Redo paragraphs above anchor if necessary.
index 21d49f91e95f93bd34d3af613ef2f6479baed40f..8cb5725ee1010570f6f5ead0e63a27bb430738c4 100644 (file)
@@ -284,6 +284,10 @@ private:
        pit_type anchor_ref_;
        ///
        int offset_ref_;
+       ///
+       void updateOffsetRef();
+       ///
+       bool need_centering_;
 
        /// keyboard mapping object.
        boost::scoped_ptr<Intl> const intl_;