3 * \file PreviewedInset.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS
11 * grfx::PreviewedInset is an abstract base class that can help insets to
12 * generate previews. The daughter class must instantiate three small
13 * methods. The Inset would own an instance of this daughter class.
16 #ifndef PREVIEWEDINSET_H
17 #define PREVIEWEDINSET_H
24 #include <boost/weak_ptr.hpp>
25 #include <boost/signals/trackable.hpp>
26 #include <boost/signals/connection.hpp>
36 class PreviewedInset : public boost::signals::trackable {
38 /// a wrapper for Previews::activated()
39 static bool activated();
42 PreviewedInset(Inset & inset) : inset_(inset), pimage_(0) {}
44 virtual ~PreviewedInset() {}
46 /** Find the PreviewLoader, add a LaTeX snippet to it and
47 * start the loading process.
49 void generatePreview();
51 /** Add a LaTeX snippet to the PreviewLoader but do not start the
54 void addPreview(PreviewLoader & ploader);
56 /** Remove a snippet from the cache of previews.
57 * Useful if previewing the contents of a file that has changed.
61 /// The preview has been generated and is ready to use.
62 bool previewReady() const;
64 /// If !previewReady() returns 0.
65 PreviewImage const * pimage() const { return pimage_; }
68 void setView(BufferView *);
71 /// Allow the daughter classes to cast up to the parent inset.
72 Inset * inset() const { return &inset_; }
74 BufferView * view() const { return view_.get(); }
77 /** This method is connected to the grfx::PreviewLoader::imageReady
80 void imageReady(PreviewImage const &) const;
82 /// Does the owning inset want a preview?
83 virtual bool previewWanted() const = 0;
84 /// a wrapper to Inset::latex
85 virtual string const latexString() const = 0;
92 boost::weak_ptr<BufferView> view_;
94 /// We don't own this. Cached for efficiency reasons.
95 mutable PreviewImage const * pimage_;
97 boost::signals::connection connection_;
103 #endif // PREVIEWEDINSET_H