]> git.lyx.org Git - lyx.git/blob - src/graphics/PreviewedInset.h
Add a monitor to the previewed image of a \input-ed file, so that the
[lyx.git] / src / graphics / PreviewedInset.h
1 // -*- C++ -*-
2 /**
3  *  \file PreviewedInset.h
4  *  Copyright 2002 the LyX Team
5  *  Read the file COPYING
6  *
7  * \author Angus Leeming <leeming@lyx.org>
8  *
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.
12  */
13
14 #ifndef PREVIEWEDINSET_H
15 #define PREVIEWEDINSET_H
16
17 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include "LString.h"
22 #include <boost/weak_ptr.hpp>
23 #include <boost/signals/trackable.hpp>
24 #include <boost/signals/connection.hpp>
25
26 class Inset;
27 class BufferView;
28
29 namespace grfx {
30
31 class PreviewImage;
32 class PreviewLoader;
33
34 class PreviewedInset : public boost::signals::trackable {
35 public:
36         /// a wrapper for Previews::activated()
37         static bool activated();
38
39         ///
40         PreviewedInset(Inset & inset) : inset_(inset), pimage_(0) {}
41         ///
42         virtual ~PreviewedInset() {}
43
44         /** Find the PreviewLoader, add a LaTeX snippet to it and
45          *  start the loading process.
46          */
47         void generatePreview();
48
49         /** Add a LaTeX snippet to the PreviewLoader but do not start the
50          *  loading process.
51          */
52         void addPreview(PreviewLoader & ploader);
53
54         /** Remove a snippet from the cache of previews.
55          *  Useful if previewing the contents of a file that has changed.
56          */
57         void removePreview();
58
59         /// The preview has been generated and is ready to use.
60         bool previewReady() const;
61
62         /// If !previewReady() returns 0.
63         PreviewImage const * pimage() const { return pimage_; }
64
65         ///
66         void setView(BufferView *);
67
68 protected:
69         /// Allow the daughter classes to cast up to the parent inset.
70         Inset * inset() const { return &inset_; }
71         ///
72         BufferView * view() const { return view_.get(); }
73
74 private:
75         /** This method is connected to the grfx::PreviewLoader::imageReady
76          *  signal.
77          */
78         void imageReady(PreviewImage const &) const;
79
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;
84
85         ///
86         Inset & inset_;
87         ///
88         string snippet_;
89         ///
90         boost::weak_ptr<BufferView> view_;
91         
92         /// We don't own this. Cached for efficiency reasons.
93         mutable PreviewImage const * pimage_;
94         ///
95         boost::signals::connection connection_;
96 };
97
98 } // namespace grfx
99
100
101 #endif // PREVIEWEDINSET_H