]> git.lyx.org Git - lyx.git/blob - src/graphics/PreviewedInset.h
Fix InsetInclude properly. Data is now stored in an InsetCommandParams
[lyx.git] / src / graphics / PreviewedInset.h
1 // -*- C++ -*-
2 /**
3  * \file PreviewedInset.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * lyx::graphics::PreviewedInset is an abstract base class that can help
12  * insets to generate previews. The daughter class must instantiate two small
13  * methods. The Inset would own an instance of this daughter class.
14  */
15
16 #ifndef PREVIEWEDINSET_H
17 #define PREVIEWEDINSET_H
18
19 #include "support/std_string.h"
20 #include <boost/signals/trackable.hpp>
21 #include <boost/signals/connection.hpp>
22
23 class Buffer;
24 class BufferView;
25 class InsetOld;
26
27
28 namespace lyx {
29 namespace graphics {
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(InsetOld & inset);
41
42         /** Find the PreviewLoader, add a LaTeX snippet to it and
43          *  start the loading process.
44          */
45         void generatePreview(Buffer const &);
46
47         /** Add a LaTeX snippet to the PreviewLoader but do not start the
48          *  loading process.
49          */
50         void addPreview(PreviewLoader & ploader);
51
52         /** Remove a snippet from the cache of previews.
53          *  Useful if previewing the contents of a file that has changed.
54          */
55         void removePreview();
56
57         /// The preview has been generated and is ready to use.
58         bool previewReady() const;
59
60         /// If !previewReady() returns 0.
61         PreviewImage const * pimage() const;
62
63 protected:
64         ///
65         virtual ~PreviewedInset() {}
66         /// Allow the daughter classes to cast up to the parent inset.
67         InsetOld const & inset() const;
68         ///
69         BufferView * view() const;
70
71 private:
72         /// This method is connected to the PreviewLoader::imageReady signal.
73         void imageReady(PreviewImage const &) const;
74
75         /// Does the owning inset want a preview?
76         virtual bool previewWanted(Buffer const &) const = 0;
77         /// a wrapper to Inset::latex
78         virtual string const latexString(Buffer const &) const = 0;
79
80         ///
81         InsetOld & inset_;
82         ///
83         string snippet_;
84
85         /// We don't own this. Cached for efficiency reasons.
86         mutable PreviewImage const * pimage_;
87         ///
88         boost::signals::connection connection_;
89 };
90
91
92 inline
93 PreviewImage const * PreviewedInset::pimage() const
94 {
95         return pimage_;
96 }
97
98
99 inline
100 InsetOld const & PreviewedInset::inset() const
101 {
102         return inset_;
103 }
104
105 } // namespace graphics
106 } // namespace lyx
107
108 #endif // PREVIEWEDINSET_H