// -*- C++ -*-
-/* This file is part of
- * =================================================
- *
- * LyX, The Document Processor
- * Copyright 1995 Matthias Ettrich.
- * Copyright 1995-2000 The LyX Team.
+/**
+ * \file GraphicsCacheItem.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * This file Copyright 2000 Baruch Even
- * ================================================= */
+ * \author Baruch Even
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ *
+ * The graphics cache is a container of grfx::CacheItems.
+ * Each grfx::CacheItem, defined here represents a separate image file.
+ *
+ * The routines here can be used to load the graphics file into memory at
+ * which point (status() == grfx::Loaded).
+ * The user is then free to access image() in order to copy it and to then
+ * transform the copy (rotate, scale, clip) and to generate the pixmap.
+ *
+ * The graphics cache supports fully asynchronous:
+ * file conversion to a loadable format;
+ * file loading.
+ *
+ * Whether you get that, of course, depends on grfx::Converter and on the
+ * grfx::Image-derived image class.
+ */
#ifndef GRAPHICSCACHEITEM_H
#define GRAPHICSCACHEITEM_H
-#include <config.h>
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-#include XPM_H_LOCATION
+#include "GraphicsTypes.h"
#include "LString.h"
-#include "sigc++/signal_system.h"
-#ifdef SIGC_CXX_NAMESPACES
-using SigC::Signal0;
-#endif
+#include <boost/utility.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <boost/signals/signal0.hpp>
+class InsetGraphics;
-/* (Baruch Even 2000-08-05)
- * This has a major drawback: it is only designed for X servers, no easy
- * porting to non X-server based platform is offered right now, this is done
- * in order to get a first version out of the door.
- *
- * Later versions should consider how to do this with more platform
- * independence, this will probably involve changing the Painter class too.
- */
+namespace grfx {
-class GraphicsCacheItem_pimpl;
-class LyXImage;
+class Image;
+class Converter;
-/// A GraphicsCache item holder.
-class GraphicsCacheItem {
+/// A grfx::Cache item holder.
+class CacheItem : boost::noncopyable {
public:
- /// d-tor, frees the image structures.
- ~GraphicsCacheItem();
- /// copy c-tor.
- GraphicsCacheItem(GraphicsCacheItem const &);
- /// Assignment operator.
- GraphicsCacheItem & operator=(GraphicsCacheItem const &);
-
- /// Return a pixmap that can be displayed on X server.
- LyXImage * getImage() const;
///
- enum ImageStatus {
- ///
- Loading = 1,
- ///
- ErrorConverting,
- ///
- ErrorReading,
- ///
- UnknownError,
- ///
- Loaded
- };
-
- /// Is the pixmap ready for display?
- ImageStatus getImageStatus() const;
-
- /** Get a notification when the image conversion is done.
- used by an internal callback mechanism.
- */
- void imageConverted(int retval);
-
- /// Create another copy of the object.
- GraphicsCacheItem * Clone() const;
-
-private:
- /// Private c-tor so that only GraphicsCache can create an instance.
- GraphicsCacheItem();
+ CacheItem(string const & file);
- /// internal copy mechanism.
- void copy(GraphicsCacheItem const &);
- /// internal destroy mechanism.
- void destroy();
-
- /// Set the filename this item will be pointing too.
- bool setFilename(string const & filename);
+ /// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
+ ~CacheItem();
///
- friend class GraphicsCache;
+ string const & filename() const;
+
+ /// It's in the cache. Now start the loading process.
+ void startLoading() const;
+ /** Monitor any changes to the file.
+ * There is no point monitoring the file before startLoading() is
+ * invoked.
+ */
+ void startMonitoring() const;
///
- GraphicsCacheItem_pimpl * pimpl;
+ bool monitoring() const;
+ /** Returns the check sum of filename() so that, for example, you can
+ * ascertain whether to output a new PostScript version of the file
+ * for a LaTeX run.
+ */
+ unsigned long checksum() const;
+
+ /** Get the image associated with filename().
+ * If the image is not yet loaded, returns 0.
+ * This routine returns a pointer to const; if you want to modify it,
+ * create a copy and modify that.
+ */
+ Image const * image() const;
+
+ /// How far have we got in loading the image?
+ ImageStatus status() const;
+
+ /** Connect and you'll be informed when the loading status of the image
+ * changes.
+ */
+ typedef boost::signal0<void>::slot_type slot_type;
+ ///
+ boost::signals::connection connect(slot_type const &) const;
+
+private:
+ /// Use the Pimpl idiom to hide the internals.
+ class Impl;
- /** The filename we refer too.
- This is used when removing ourselves from the cache.
- */
- string filename_;
+ /// The pointer never changes although *pimpl_'s contents may.
+ boost::scoped_ptr<Impl> const pimpl_;
};
-#endif
+} // namespace grfx
+
+#endif // GRAPHICSCACHEITEM_H