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 /// The preview has been generated and is ready to use.
55 bool previewReady() const;
57 /// If !previewReady() returns 0.
58 PreviewImage const * pimage() const { return pimage_; }
61 void setView(BufferView *);
64 /// Allow the daughter classes to cast up to the parent inset.
65 Inset * inset() const { return &inset_; }
67 BufferView * view() const { return view_.get(); }
70 /** This method is connected to the grfx::PreviewLoader::imageReady
73 void imageReady(PreviewImage const &) const;
75 /// Does the owning inset want a preview?
76 virtual bool previewWanted() const = 0;
77 /// a wrapper to Inset::latex
78 virtual string const latexString() const = 0;
85 boost::weak_ptr<BufferView> view_;
87 /// We don't own this. Cached for efficiency reasons.
88 mutable PreviewImage const * pimage_;
90 boost::signals::connection connection_;
96 #endif // PREVIEWEDINSET_H