X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fgraphics%2FGraphicsCacheItem.h;h=6f7f968bc6a44086af831849470043faa4053c0e;hb=b92ceba9a1b6483eae74877fd84b2bfc114846bf;hp=8f597dfffb413c8698120809f7d9681a251c45b1;hpb=9ab27bcd7e601aedc6253808007105f4e4545661;p=lyx.git diff --git a/src/graphics/GraphicsCacheItem.h b/src/graphics/GraphicsCacheItem.h index 8f597dfffb..6f7f968bc6 100644 --- a/src/graphics/GraphicsCacheItem.h +++ b/src/graphics/GraphicsCacheItem.h @@ -1,114 +1,103 @@ // -*- 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 graphics::CacheItems. + * Each graphics::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() == graphics::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 graphics::Converter and + * on the graphics::Image-derived image class. + */ #ifndef GRAPHICSCACHEITEM_H #define GRAPHICSCACHEITEM_H -#include +#include "GraphicsTypes.h" -#ifdef __GNUG__ -#pragma interface -#endif +#include "support/signals.h" -#include XPM_H_LOCATION -#include "LString.h" -#include "graphics/Renderer.h" -#include "support/syscall.h" -#include "sigc++/signal_system.h" -#ifdef SIGC_CXX_NAMESPACES -using SigC::Signal0; -#endif +namespace lyx { -/* (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 support { class FileName; } -/* (Baruch Even 2000-08-05) - * This should be made reference counted, but for the sake of initial design - * I'll forego that and just make a first version that actually works, though - * it may fail or leak in real document, this is an initial design to try - * ideas on and be a testbed. - * It may just as well be scraped later on to create a better design based on - * the results of working with the current design. - */ +namespace graphics { -/// A GraphicsCache item holder. -class GraphicsCacheItem { +class Image; +class Converter; + +/// A graphics::Cache item holder. +class CacheItem { public: - /// d-tor, frees the image structures. - ~GraphicsCacheItem(); - - /// Get the height of the image. Returns -1 on error. - int getHeight() const { return height_; } - - /// Get the width of the image. Returns -1 on error. - int getWidth() const { return width_; } - - /// Return a pixmap that can be displayed on X server. - Pixmap getImage() const { return pixmap_; } - - enum ImageStatus { - Loading = 1, - ErrorConverting, - ErrorReading, - Loaded - }; - - /// Is the pixmap ready for display? - ImageStatus getImageStatus() const { return imageStatus_; } - - /// Get a notification when the image conversion is done. - /// used by an internal callback mechanism. - void imageConverted(int retval); - - /// A signal objects can connect to in order to know when the image - /// has arrived. - Signal0 imageDone; + /// + CacheItem(support::FileName const & file, support::FileName const & doc_file); + /// Needed for the pimpl + ~CacheItem(); + + /// + support::FileName const & filename() const; + + /// Try to load a display format. + bool tryDisplayFormat() 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; + /// + bool monitoring() const; + /// perform a modification check asynchronously + void checkModifiedAsync() 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 signals2::signal::slot_type slot_type; + /// + signals2::connection connect(slot_type const &) const; + private: - /// Private c-tor so that only GraphicsCache can create an instance. - GraphicsCacheItem(); - - /// Set the filename this item will be pointing too. - bool setFilename(string const & filename); - - /// Create an XPM file version of the image. - bool renderXPM(string const & filename); - - /// Load the image from XPM to memory Pixmap - void loadXPMImage(); - - /// - friend class GraphicsCache; - - /// The file name of the XPM file. - string xpmfile; - /// The image height - int height_; - /// The image width - int width_; - /// Is the pixmap loaded? - ImageStatus imageStatus_; - /// The image pixmap - Pixmap pixmap_; - /// The rendering object. - Renderer * renderer; - - /// The system caller, runs the convertor. - Systemcalls syscall; + /// noncopyable + CacheItem(CacheItem const &); + void operator=(CacheItem const &); + + /// Use the Pimpl idiom to hide the internals. + class Impl; + /// The pointer never changes although *pimpl_'s contents may. + Impl * const pimpl_; }; -#endif +} // namespace graphics +} // namespace lyx + +#endif // GRAPHICSCACHEITEM_H