]> git.lyx.org Git - lyx.git/blob - src/insets/render_preview.h
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[lyx.git] / src / insets / render_preview.h
1 // -*- C++ -*-
2 /**
3  * \file render_preview.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  * graphics::RenderPreview 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 RENDER_PREVIEW_H
17 #define RENDER_PREVIEW_H
18
19 #include "render_base.h"
20
21 #include "support/FileMonitor.h"
22 #include "support/docstring.h"
23
24 #include <boost/signal.hpp>
25 #include <boost/signals/trackable.hpp>
26 #include <boost/signals/connection.hpp>
27
28 namespace lyx {
29
30 class Buffer;
31 class LyXRC_PreviewStatus;
32 class MetricsInfo;
33 class PainterInfo;
34
35 namespace support { class FileName; }
36
37 namespace graphics {
38
39 class PreviewImage;
40 class PreviewLoader;
41
42 } // namespace graphics
43
44
45 class RenderPreview : public RenderBase, public boost::signals::trackable {
46 public:
47         /// a wrapper for Previews::status()
48         static LyXRC_PreviewStatus status();
49
50         RenderPreview(InsetBase const *);
51         RenderPreview(RenderPreview const &, InsetBase const *);
52         std::auto_ptr<RenderBase> clone(InsetBase const *) const;
53
54         /// Compute the size of the object, returned in dim
55         bool metrics(MetricsInfo &, Dimension & dim) const;
56         ///
57         void draw(PainterInfo & pi, int x, int y) const;
58
59         /** Find the PreviewLoader and add a LaTeX snippet to it.
60          *  Do not start the loading process.
61          */
62         void addPreview(docstring const & latex_snippet, Buffer const &);
63
64         /** Add a LaTeX snippet to the PreviewLoader.
65          *  Do not start the loading process.
66          */
67         void addPreview(docstring const & latex_snippet,
68                         graphics::PreviewLoader & ploader);
69
70         /// Begin the loading process.
71         void startLoading(Buffer const & buffer) const;
72
73         /** Remove a snippet from the cache of previews.
74          *  Useful if previewing the contents of a file that has changed.
75          */
76         void removePreview(Buffer const &);
77
78         /** \returns a pointer to the PreviewImage associated with this snippet
79          *  of latex.
80          */
81         graphics::PreviewImage const *
82         getPreviewImage(Buffer const & buffer) const;
83
84         /// equivalent to dynamic_cast
85         virtual RenderPreview * asPreview() { return this; }
86
87 private:
88         /// Not implemented.
89         RenderPreview & operator=(RenderPreview const &);
90
91         /// This method is connected to the PreviewLoader::imageReady signal.
92         void imageReady(graphics::PreviewImage const &);
93
94         /// The thing that we're trying to generate a preview of.
95         std::string snippet_;
96
97         /** Store the connection to the preview loader so that we connect
98          *  only once.
99          */
100         boost::signals::connection ploader_connection_;
101
102         /// Inform the core that the inset has changed.
103         InsetBase const * parent_;
104 };
105
106
107 class RenderMonitoredPreview : public RenderPreview {
108 public:
109         RenderMonitoredPreview(InsetBase const *);
110         ///
111         void draw(PainterInfo & pi, int x, int y) const;
112         ///
113         void setAbsFile(support::FileName const & file);
114         ///
115         bool monitoring() const { return monitor_.monitoring(); }
116         void startMonitoring() const { monitor_.start(); }
117         void stopMonitoring() const { monitor_.stop(); }
118
119         /// Connect and you'll be informed when the file changes.
120         typedef support::FileMonitor::slot_type slot_type;
121         boost::signals::connection fileChanged(slot_type const &);
122
123         /// equivalent to dynamic_cast
124         virtual RenderMonitoredPreview * asMonitoredPreview() { return this; }
125
126 private:
127         ///
128         mutable support::FileMonitor monitor_;
129 };
130
131 } // namespace lyx
132
133 #endif // RENDERPREVIEW_H