3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
14 #include "PreviewLoader.h"
17 #include "insetiterator.h"
19 #include "paragraph.h"
21 #include "insets/Inset.h"
28 LyXRC_PreviewStatus Previews::status()
34 Previews & Previews::get()
36 static Previews singleton;
41 class Previews::Impl {
44 typedef boost::shared_ptr<PreviewLoader> PreviewLoaderPtr;
46 typedef std::map<Buffer const *, PreviewLoaderPtr> CacheType;
61 PreviewLoader & Previews::loader(Buffer const & buffer) const
63 Impl::CacheType::iterator it = pimpl_->cache.find(&buffer);
65 if (it == pimpl_->cache.end()) {
66 Impl::PreviewLoaderPtr ptr(new PreviewLoader(buffer));
67 pimpl_->cache[&buffer] = ptr;
71 return *it->second.get();
75 void Previews::removeLoader(Buffer const & buffer) const
77 Impl::CacheType::iterator it = pimpl_->cache.find(&buffer);
79 if (it != pimpl_->cache.end())
80 pimpl_->cache.erase(it);
84 void Previews::generateBufferPreviews(Buffer const & buffer) const
86 PreviewLoader & ploader = loader(buffer);
88 InsetBase & inset = buffer.inset();
89 InsetIterator it = inset_iterator_begin(inset);
90 InsetIterator const end = inset_iterator_end(inset);
92 for (; it != end; ++it)
93 it->addPreview(ploader);
95 ploader.startLoading();
98 } // namespace graphics