]> git.lyx.org Git - features.git/commitdiff
Andreas' patch to prevent crash on click on previewd inset
authorAndré Pönitz <poenitz@gmx.net>
Mon, 18 Jul 2005 00:45:10 +0000 (00:45 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 18 Jul 2005 00:45:10 +0000 (00:45 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10309 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/math_hullinset.C
src/mathed/math_hullinset.h
src/mathed/math_nestinset.C

index 70d2f71ea1fa17e4f4ed8ae91d7cc9b58cdc4f53..5539190a96d590fbced946fd1db3694fab4197ad 100644 (file)
@@ -187,7 +187,7 @@ MathHullInset & MathHullInset::operator=(MathHullInset const & other)
 
 InsetBase * MathHullInset::editXY(LCursor & cur, int x, int y)
 {
-       if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
+       if (use_preview_) {
                edit(cur, true);
                return this;
        }
@@ -244,25 +244,24 @@ int MathHullInset::defaultColSpace(col_type col)
 
 char const * MathHullInset::standardFont() const
 {
-       if (type_ == "none")
-               return "lyxnochange";
-       return "mathnormal";
+       return type_ == "none" ? "lyxnochange" : "mathnormal";
 }
 
 
-void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
+bool MathHullInset::previewState(BufferView * bv) const
 {
-       BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
-
-       bool use_preview = false;
-       if (!editing(mi.base.bv) &&
-           RenderPreview::status() == LyXRC::PREVIEW_ON) {
+       if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
                lyx::graphics::PreviewImage const * pimage =
-                       preview_->getPreviewImage(*mi.base.bv->buffer());
-               use_preview = pimage && pimage->image();
+                       preview_->getPreviewImage(*bv->buffer());
+               return pimage && pimage->image();
        }
+       return false;
+}
 
-       if (use_preview) {
+
+void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       if (previewState(mi.base.bv)) {
                preview_->metrics(mi, dim);
                // insert a one pixel gap in front of the formula
                dim.wid += 1;
@@ -306,17 +305,9 @@ void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void MathHullInset::draw(PainterInfo & pi, int x, int y) const
 {
-       BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
-
-       bool use_preview = false;
-       if (!editing(pi.base.bv) &&
-           RenderPreview::status() == LyXRC::PREVIEW_ON) {
-               lyx::graphics::PreviewImage const * pimage =
-                       preview_->getPreviewImage(*pi.base.bv->buffer());
-               use_preview = pimage && pimage->image();
-       }
+       use_preview_ = previewState(pi.base.bv);
 
-       if (use_preview) {
+       if (use_preview_) {
                // one pixel gap in front
                preview_->draw(pi, x + 1, y);
                setPosCache(pi, x, y);
index 9793d8eaab22fe614a692ba8b5d9aa313e3f9a83..98d9ae869b32dfe8668ead8fb335b5a05b519971 100644 (file)
@@ -177,6 +177,8 @@ private:
        std::vector<std::string> label_;
        ///
        boost::scoped_ptr<RenderPreview> preview_;
+       ///
+       mutable bool use_preview_;
 //
 // Incorporate me
 //
@@ -202,9 +204,12 @@ public:
 
 protected:
        ///
-       void handleFont(LCursor &, std::string const & arg, std::string const & font);
+       void handleFont(LCursor & cur, std::string const & arg,
+               std::string const & font);
+       ///
+       void handleFont2(LCursor & cur, std::string const & arg);
        ///
-       void handleFont2(LCursor &, std::string const & arg);
+       bool previewState(BufferView * bv) const;
 };
 
 #endif
index db2e556b305c1d61cc61ffa2f014025030cc8d97..a71327a84e455bbe11473dd3744f4dc27cc79d51 100644 (file)
@@ -458,6 +458,7 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_FINISHED_DOWN:
+               ++cur.pos();
                cur.bv().cursor() = cur;
                break;