]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/PreviewImage.cpp
Add \makeat switches to babel settings if necessary.
[lyx.git] / src / graphics / PreviewImage.cpp
index 02af7c470a7239c2297afbf34907a626aae901ca..58e25fbd06122d2fc4126635a059c7f32c145db0 100644 (file)
 #include "PreviewLoader.h"
 
 #include "support/FileName.h"
-#include "support/lyxlib.h"
 
-#include <boost/bind.hpp>
-
-using std::string;
+#include "support/bind.h"
 
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
-
-using support::FileName;
-
 namespace graphics {
 
 class PreviewImage::Impl : public boost::signals::trackable {
@@ -74,31 +70,23 @@ string const & PreviewImage::snippet() const
 }
 
 
-int PreviewImage::ascent() const
+support::FileName const & PreviewImage::filename() const
 {
-       Image const * const image = pimpl_->iloader_.image();
-       if (!image)
-               return 0;
-
-       return int(pimpl_->ascent_frac_ * double(image->getHeight()));
+       return pimpl_->iloader_.filename();
 }
 
 
-int PreviewImage::descent() const
+Dimension PreviewImage::dim() const
 {
+       Dimension dim;
        Image const * const image = pimpl_->iloader_.image();
        if (!image)
-               return 0;
+               return dim;
 
-       // Avoids rounding errors.
-       return image->getHeight() - ascent();
-}
-
-
-int PreviewImage::width() const
-{
-       Image const * const image = pimpl_->iloader_.image();
-       return image ? image->getWidth() : 0;
+       dim.asc = int(pimpl_->ascent_frac_ * double(image->height()));
+       dim.des = image->height() - dim.asc;
+       dim.wid = image->width();
+       return dim;
 }
 
 
@@ -115,13 +103,13 @@ PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
        : parent_(p), ploader_(l), iloader_(bf),
          snippet_(s), ascent_frac_(af)
 {
-       iloader_.connect(boost::bind(&Impl::statusChanged, this));
+       iloader_.connect(bind(&Impl::statusChanged, this));
 }
 
 
 PreviewImage::Impl::~Impl()
 {
-       support::unlink(iloader_.filename());
+       iloader_.filename().removeFile();
 }
 
 
@@ -149,12 +137,15 @@ void PreviewImage::Impl::statusChanged()
        case ErrorLoading:
        case ErrorGeneratingPixmap:
        case ErrorUnknown:
-               //lyx::unlink(iloader_.filename());
+               //iloader_.filename().removeFile();
                ploader_.remove(snippet_);
-               break;
+               // FIXME: We need to return here, because PreviewLoader::remove
+               // removes the preview image from the cache, which deletes this
+               // object, so we should not try to do anything here.
+               return;
 
        case Ready:
-               support::unlink(iloader_.filename());
+               iloader_.filename().removeFile();
                break;
        }
        ploader_.emitSignal(parent_);