3 * \file PreviewedInset.h
4 * Copyright 2002 the LyX Team
5 * Read the file COPYING
7 * \author Angus Leeming <leeming@lyx.org>
9 * grfx::PreviewedInset is an abstract base class that can help insets to
10 * generate previews. The daughter class must instantiate three small
11 * methods. The Inset would own an instance of this daughter class.
14 #ifndef PREVIEWEDINSET_H
15 #define PREVIEWEDINSET_H
22 #include <boost/weak_ptr.hpp>
23 #include <boost/signals/trackable.hpp>
24 #include <boost/signals/connection.hpp>
34 class PreviewedInset : public boost::signals::trackable {
36 /// a wrapper for Previews::activated()
37 static bool activated();
40 PreviewedInset(Inset & inset) : inset_(inset), pimage_(0) {}
42 virtual ~PreviewedInset() {}
44 /** Find the PreviewLoader, add a LaTeX snippet to it and
45 * start the loading process.
47 void generatePreview();
49 /** Add a LaTeX snippet to the PreviewLoader but do not start the
52 void addPreview(PreviewLoader & ploader);
54 /** Remove a snippet from the cache of previews.
55 * Useful if previewing the contents of a file that has changed.
59 /// The preview has been generated and is ready to use.
60 bool previewReady() const;
62 /// If !previewReady() returns 0.
63 PreviewImage const * pimage() const { return pimage_; }
66 void setView(BufferView *);
69 /// Allow the daughter classes to cast up to the parent inset.
70 Inset * inset() const { return &inset_; }
72 BufferView * view() const { return view_.get(); }
75 /** This method is connected to the grfx::PreviewLoader::imageReady
78 void imageReady(PreviewImage const &) const;
80 /// Does the owning inset want a preview?
81 virtual bool previewWanted() const = 0;
82 /// a wrapper to Inset::latex
83 virtual string const latexString() const = 0;
90 boost::weak_ptr<BufferView> view_;
92 /// We don't own this. Cached for efficiency reasons.
93 mutable PreviewImage const * pimage_;
95 boost::signals::connection connection_;
101 #endif // PREVIEWEDINSET_H