2000-07-31 12:30:10 +00:00
|
|
|
// -*- C++ -*-
|
2002-02-27 09:59:52 +00:00
|
|
|
/*
|
|
|
|
* \file GraphicsCacheItem.h
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
2000-07-31 12:30:10 +00:00
|
|
|
*
|
2002-02-27 09:59:52 +00:00
|
|
|
* \author Baruch Even <baruch.even@writeme.com>
|
|
|
|
* \author Angus Leeming <a.leeming@ic.ac.uk>
|
|
|
|
*
|
|
|
|
* The graphics cache is a container of GCacheItems. Each GCacheItem, defined
|
|
|
|
* here represents a separate image file. However, each file can be viewed in
|
|
|
|
* different ways (different sizes, rotations etc), so each GCacheItem itself
|
|
|
|
* contains a list of ModifiedItems, also defined here. Each ModifiedItem
|
|
|
|
* has a GParams variable that defines the way it will be viewed. It also
|
|
|
|
* contains a list of the graphics insets that refer to it, so calls through
|
|
|
|
* the GCache to GCacheItem ultimately return the loading status and image
|
|
|
|
* for that particular graphics inset.
|
|
|
|
*
|
|
|
|
* The graphics cache supports fully asynchronous:
|
|
|
|
* file conversion to a loadable format;
|
|
|
|
* file loading.
|
|
|
|
*
|
|
|
|
* Whether you get that, of course, depends on grfx::GConverter and on the
|
|
|
|
* grfx::GImage-derived image class.
|
|
|
|
*
|
|
|
|
* Image modification (scaling, rotation etc) is blocking.
|
|
|
|
*/
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
#ifndef GRAPHICSCACHEITEM_H
|
|
|
|
#define GRAPHICSCACHEITEM_H
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
#include "GraphicsTypes.h"
|
2000-08-08 09:18:39 +00:00
|
|
|
#include "LString.h"
|
2002-05-22 01:16:37 +00:00
|
|
|
|
2001-02-22 16:53:59 +00:00
|
|
|
#include <boost/utility.hpp>
|
2002-05-22 01:16:37 +00:00
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
2001-03-15 18:21:56 +00:00
|
|
|
#include <sigc++/signal_system.h>
|
2000-08-10 13:15:05 +00:00
|
|
|
|
2002-05-22 01:16:37 +00:00
|
|
|
#include <list>
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
class InsetGraphics;
|
|
|
|
|
|
|
|
namespace grfx {
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
class GParams;
|
|
|
|
class ModifiedItem;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// A grfx::GCache item holder.
|
|
|
|
class GCacheItem : boost::noncopyable, public SigC::Object {
|
2000-07-31 12:30:10 +00:00
|
|
|
public:
|
2002-02-27 09:59:52 +00:00
|
|
|
/// the GCacheItem contains data of this type.
|
|
|
|
typedef boost::shared_ptr<ModifiedItem> ModifiedItemPtr;
|
|
|
|
|
2000-08-14 15:31:16 +00:00
|
|
|
///
|
2002-02-27 09:59:52 +00:00
|
|
|
GCacheItem(InsetGraphics const &, GParams const &);
|
|
|
|
|
|
|
|
/// The params have changed (but still refer to this file).
|
|
|
|
void modify(InsetGraphics const &, GParams const &);
|
|
|
|
|
|
|
|
/// Remove the reference to this inset.
|
|
|
|
void remove(InsetGraphics const &);
|
|
|
|
|
|
|
|
/// It's in the cache. Now start the loading process.
|
|
|
|
void startLoading(InsetGraphics const &);
|
|
|
|
|
|
|
|
/// Is the cache item referenced by any insets at all?
|
|
|
|
bool empty() const;
|
|
|
|
|
|
|
|
/// The name of the original image file.
|
|
|
|
string const & filename() const;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Is this image file referenced by this inset?
|
|
|
|
bool referencedBy(InsetGraphics const &) const;
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/** Returns the image referenced by this inset (or an empty container
|
|
|
|
* if it's not yet loaded.
|
|
|
|
*/
|
|
|
|
ImagePtr const image(InsetGraphics const &) const;
|
|
|
|
|
|
|
|
/// The loading status of the image referenced by this inset.
|
|
|
|
ImageStatus status(InsetGraphics const &) const;
|
|
|
|
|
|
|
|
/** If (changed_background == true), then the background color of the
|
|
|
|
* graphics inset has changed. Update all images.
|
|
|
|
* Else, the preferred display type has changed.
|
|
|
|
* Update the view of all insets whose display type is DEFAULT.
|
|
|
|
*/
|
|
|
|
void changeDisplay(bool changed_background);
|
2000-08-08 09:18:39 +00:00
|
|
|
|
2002-04-11 17:40:44 +00:00
|
|
|
/// Used to ascertain the Bounding Box of non (e)ps files.
|
|
|
|
unsigned int raw_width() const;
|
|
|
|
///
|
|
|
|
unsigned int raw_height() const;
|
2002-05-22 01:16:37 +00:00
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
private:
|
2002-02-27 09:59:52 +00:00
|
|
|
/** Start the image conversion process, checking first that it is
|
|
|
|
* necessary. If it is necessary, then a conversion task is started.
|
|
|
|
* GCacheItem asumes that the conversion is asynchronous and so
|
|
|
|
* passes a Signal to the converting routine. When the conversion
|
|
|
|
* is finished, this Signal is emitted, returning the converted
|
|
|
|
* file to this->imageConverted.
|
2001-07-17 00:38:04 +00:00
|
|
|
*
|
2002-02-27 09:59:52 +00:00
|
|
|
* If no file conversion is needed, then convertToDisplayFormat() calls
|
|
|
|
* loadImage() directly.
|
|
|
|
*
|
|
|
|
* convertToDisplayFormat() will set the loading status flag as
|
|
|
|
* approriate through calls to setStatus().
|
2001-07-17 00:38:04 +00:00
|
|
|
*/
|
2002-02-27 09:59:52 +00:00
|
|
|
void convertToDisplayFormat();
|
2001-07-17 00:38:04 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/** Load the image into memory. This is called either from
|
|
|
|
* convertToDisplayFormat() direct or from imageConverted().
|
|
|
|
*/
|
2001-04-02 19:56:48 +00:00
|
|
|
void loadImage();
|
2000-08-10 13:15:05 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/** Get a notification when the image conversion is done.
|
|
|
|
* Connected to a signal on_finish_ which is passed to
|
|
|
|
* GConverter::convert.
|
|
|
|
*/
|
|
|
|
void imageConverted(string const & file_to_load);
|
|
|
|
|
|
|
|
/** Get a notification when the image loading is done.
|
|
|
|
* Connected to a signal on_finish_ which is passed to
|
|
|
|
* GImage::loadImage.
|
|
|
|
*/
|
|
|
|
void imageLoaded(bool);
|
|
|
|
|
|
|
|
/// How far have we got in loading the original, unmodified image?
|
2002-03-21 17:27:08 +00:00
|
|
|
ImageStatus status() const;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/** Sets the status of the loading process. Also notifies
|
|
|
|
* listeners that the status has chacnged.
|
|
|
|
*/
|
2001-07-17 00:38:04 +00:00
|
|
|
void setStatus(ImageStatus new_status);
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// The filename we refer too.
|
2000-08-10 13:15:05 +00:00
|
|
|
string filename_;
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Is the file compressed?
|
|
|
|
bool zipped_;
|
|
|
|
/// If so, store the uncompressed file in this temporary file.
|
|
|
|
string unzipped_filename_;
|
|
|
|
/// What file are we trying to load?
|
|
|
|
string file_to_load_;
|
|
|
|
/** Should we delete the file after loading? True if the file is
|
|
|
|
* the result of a conversion process.
|
|
|
|
*/
|
|
|
|
bool remove_loaded_file_;
|
|
|
|
|
|
|
|
/// The original, unmodified image and its loading status.
|
|
|
|
ImagePtr image_;
|
|
|
|
///
|
|
|
|
ImageStatus status_;
|
|
|
|
|
|
|
|
/** A SignalLoadTypePtr is connected to this->imageLoaded and
|
|
|
|
* then passed to ImagePtr::load.
|
|
|
|
* When the image has been loaded, the signal is emitted.
|
|
|
|
*
|
|
|
|
* We pass a shared_ptr because it is eminently possible for the
|
|
|
|
* ModifiedItem to be destructed before the loading is complete and
|
|
|
|
* the signal must remain in scope. It doesn't matter if the slot
|
|
|
|
* disappears, SigC takes care of that.
|
|
|
|
*/
|
|
|
|
typedef SigC::Signal1<void, bool> SignalLoadType;
|
|
|
|
///
|
|
|
|
typedef boost::shared_ptr<SignalLoadType> SignalLoadTypePtr;
|
|
|
|
|
|
|
|
/// The connection of the signal passed to ImagePtr::loadImage.
|
|
|
|
SigC::Connection cl_;
|
|
|
|
|
|
|
|
/** A SignalConvertTypePtr is connected to this->imageConverted and
|
|
|
|
* then passed to GConverter::convert.
|
|
|
|
* When the image has been converted to a loadable format, the signal
|
|
|
|
* is emitted, returning the name of the loadable file to
|
|
|
|
* imageConverted.
|
|
|
|
*/
|
|
|
|
typedef SigC::Signal1<void, string const &> SignalConvertType;
|
|
|
|
///
|
|
|
|
typedef boost::shared_ptr<SignalConvertType> SignalConvertTypePtr;
|
|
|
|
|
|
|
|
/// The connection of the signal passed to GConverter::convert.
|
|
|
|
SigC::Connection cc_;
|
|
|
|
|
|
|
|
/// The list of all modified images.
|
|
|
|
typedef std::list<ModifiedItemPtr> ListType;
|
|
|
|
///
|
|
|
|
ListType modified_images;
|
2000-07-31 12:30:10 +00:00
|
|
|
};
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-03-11 22:58:05 +00:00
|
|
|
///
|
2002-02-27 09:59:52 +00:00
|
|
|
class ModifiedItem {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
ModifiedItem(InsetGraphics const &, GParams const &, ImagePtr const &);
|
|
|
|
|
|
|
|
///
|
|
|
|
GParams const & params() { return *p_.get(); }
|
|
|
|
|
|
|
|
/// Add inset to the list of insets.
|
|
|
|
void add(InsetGraphics const & inset);
|
|
|
|
|
|
|
|
/// Remove inset from the list of insets.
|
|
|
|
void remove(InsetGraphics const & inset);
|
|
|
|
|
|
|
|
///
|
|
|
|
bool empty() const { return insets.empty(); }
|
|
|
|
|
|
|
|
/// Is this ModifiedItem referenced by inset?
|
|
|
|
bool referencedBy(InsetGraphics const & inset) const;
|
|
|
|
|
|
|
|
///
|
|
|
|
ImagePtr const image() const;
|
|
|
|
|
|
|
|
/// How far have we got in loading the modified image?
|
|
|
|
ImageStatus status() const { return status_; }
|
|
|
|
|
|
|
|
/** Called from GCacheItem once the raw image is loaded.
|
|
|
|
* Modifies the image in accord with p_.
|
|
|
|
*/
|
|
|
|
void modify(ImagePtr const &);
|
|
|
|
|
|
|
|
/// Updates the pixmap.
|
|
|
|
void setPixmap();
|
|
|
|
|
|
|
|
/** changeDisplay returns a full ModifiedItemPtr if any of the
|
|
|
|
* insets have display=DEFAULT and if that DEFAULT value has
|
|
|
|
* changed.
|
|
|
|
* If this occurs, then this has these insets removed.
|
|
|
|
*/
|
|
|
|
boost::shared_ptr<ModifiedItem> changeDisplay();
|
|
|
|
|
|
|
|
///
|
|
|
|
typedef std::list<InsetGraphics const *> ListType;
|
|
|
|
|
|
|
|
/// Make these accessible for changeDisplay.
|
|
|
|
ListType insets;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/** Sets the status of the loading process. Also notifies
|
|
|
|
* listeners that the status has changed.
|
|
|
|
*/
|
|
|
|
void setStatus(ImageStatus new_status);
|
|
|
|
|
|
|
|
/// The original and modified images and its loading status.
|
|
|
|
ImagePtr original_image_;
|
|
|
|
///
|
|
|
|
ImagePtr modified_image_;
|
|
|
|
///
|
|
|
|
ImageStatus status_;
|
2002-03-21 17:27:08 +00:00
|
|
|
///
|
2002-02-27 09:59:52 +00:00
|
|
|
boost::shared_ptr<GParams> p_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace grfx
|
|
|
|
|
|
|
|
#endif // GRAPHICSCACHEITEM_H
|