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