]> git.lyx.org Git - lyx.git/blob - src/insets/InsetPreview.h
b221d50b6031293247a944a11f43c19aa9a88d6f
[lyx.git] / src / insets / InsetPreview.h
1 // -*- C++ -*-\r
2 /**\r
3  * \file InsetPreview.h\r
4  * This file is part of LyX, the document processor.\r
5  * Licence details can be found in the file COPYING.\r
6  *\r
7  * \author Vincent van Ravesteijn\r
8  *\r
9  * Full author contact details are available in file CREDITS.\r
10  */\r
11 \r
12 #ifndef INSETPREVIEW_H\r
13 #define INSETPREVIEW_H\r
14 \r
15 #include "InsetText.h"\r
16 \r
17 #include "Dimension.h"\r
18 \r
19 #include <boost/scoped_ptr.hpp>\r
20 \r
21 namespace lyx {\r
22 \r
23 class RenderPreview;\r
24 \r
25 namespace graphics {\r
26         class PreviewLoader;\r
27 }\r
28 \r
29 /// An inset with an instant preview\r
30 class InsetPreview : public InsetText {\r
31         \r
32 public:\r
33         ///\r
34         InsetPreview(Buffer *);\r
35         ///\r
36         ~InsetPreview();\r
37         ///\r
38         InsetPreview(InsetPreview const & other);\r
39 \r
40         /// \name Methods inherited from Inset class\r
41         //@{\r
42         Inset * clone() const { return new InsetPreview(*this); }\r
43 \r
44         bool neverIndent() const { return true; }\r
45         \r
46         InsetCode lyxCode() const { return PREVIEW_CODE; }\r
47         \r
48         docstring name() const { return from_ascii("Preview"); }\r
49         \r
50         bool descendable(BufferView const & /*bv*/) const { return true; }\r
51 \r
52         docstring contextMenu(BufferView const &, int, int) const\r
53                 { return from_ascii("context-preview"); }\r
54 \r
55         void metrics(MetricsInfo & mi, Dimension & dim) const;\r
56 \r
57         Inset * editXY(Cursor & cur, int x, int y);\r
58 \r
59         void draw(PainterInfo & pi, int x, int y) const;\r
60 \r
61         void addPreview(DocIterator const & inset_pos,\r
62                 graphics::PreviewLoader & ploader) const;\r
63 \r
64         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);\r
65 \r
66         void write(std::ostream & os) const;\r
67 \r
68         void edit(Cursor & cur, bool front, EntryDirection entry_from);\r
69         //@}\r
70         \r
71 protected:\r
72         /// Retrieves the preview state. Returns true if preview\r
73         /// is enabled and the preview image is availabled.\r
74         bool previewState(BufferView * bv) const;\r
75         /// Recreates the preview if preview is enabled.\r
76         void reloadPreview(DocIterator const & pos) const;\r
77         /// Prepare the preview if preview is enabled.\r
78         void preparePreview(DocIterator const & pos) const;\r
79 \r
80         ///\r
81         boost::scoped_ptr<RenderPreview> preview_;\r
82         ///\r
83         mutable bool use_preview_;\r
84 \r
85 private:\r
86         ///\r
87         mutable Dimension dim_;\r
88 };\r
89 \r
90 \r
91 } // namespace lyx\r
92 \r
93 \r
94 #endif\r
95 \r