2 * \file GraphicsCache.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author Baruch Even <baruch.even@writeme.com>
7 * \author Angus Leeming <a.leeming@ic.ac.uk>
13 #pragma implementation
16 #include "GraphicsCache.h"
17 #include "GraphicsCacheItem.h"
18 #include "GraphicsImage.h"
19 #include "GraphicsParams.h"
20 #include "insets/insetgraphics.h"
23 // I think that graphicsInit should become a new Dialogs::graphicsInit
25 // These #includes would then be moved to Dialogs.C.
27 #include "GraphicsImageXPM.h"
28 //#include "xformsGraphicsImage.h"
37 // connect the image loader based on the XPM library
38 GImage::newImage.connect(slot(&GImageXPM::newImage));
39 GImage::loadableFormats.connect(slot(&GImageXPM::loadableFormats));
40 // connect the image loader based on the xforms library
41 // GImage::newImage.connect(slot(&xformsGImage::newImage));
42 // GImage::loadableFormats.connect(slot(&xformsGImage::loadableFormats));
50 GCache & GCache::get()
52 static bool start = true;
58 // Now return the cache
59 static GCache singleton;
66 cache = new CacheType;
70 // all elements are destroyed by the shared_ptr's in the map.
77 void GCache::update(InsetGraphics const & inset)
79 // A subset only of InsetGraphicsParams is needed for display purposes.
80 // The GraphicsParams c-tor also interrogates lyxrc to ascertain whether
82 GParams params(inset.params());
84 // Each inset can reference only one file, so check the cache for any
85 // graphics files referenced by inset. If the name of this file is
86 // different from that in params, then remove the reference.
87 CacheType::iterator it = find(inset);
89 if (it != cache->end()) {
90 CacheItemType item = it->second;
91 if (item->filename() != params.filename) {
98 // Are we adding a new file or modifying the display of an existing one?
99 it = cache->find(params.filename);
101 if (it != cache->end()) {
102 it->second->modify(inset, params);
106 CacheItemType item(new GCacheItem(inset, params));
108 (*cache)[params.filename] = item;
112 void GCache::remove(InsetGraphics const & inset)
114 CacheType::iterator it = find(inset);
115 if (it == cache->end())
118 CacheItemType item = it->second;
126 void GCache::startLoading(InsetGraphics const & inset)
128 CacheType::iterator it = find(inset);
129 if (it == cache->end())
132 it->second->startLoading(inset);
136 ImagePtr const GCache::image(InsetGraphics const & inset) const
138 CacheType::const_iterator it = find(inset);
139 if (it == cache->end())
142 return it->second->image(inset);
146 ImageStatus GCache::status(InsetGraphics const & inset) const
148 CacheType::const_iterator it = find(inset);
149 if (it == cache->end())
152 return it->second->status(inset);
156 void GCache::changeDisplay(bool changed_background)
158 CacheType::iterator it = cache->begin();
159 CacheType::iterator end = cache->end();
160 for(; it != end; ++it)
161 it->second->changeDisplay(changed_background);
165 GCache::CacheType::iterator
166 GCache::find(InsetGraphics const & inset)
168 CacheType::iterator it = cache->begin();
169 for (; it != cache->end(); ++it) {
170 if (it->second->referencedBy(inset))
178 GCache::CacheType::const_iterator
179 GCache::find(InsetGraphics const & inset) const
181 CacheType::const_iterator it = cache->begin();
182 for (; it != cache->end(); ++it) {
183 if (it->second->referencedBy(inset))