]> git.lyx.org Git - lyx.git/blob - src/insets/InsetPreview.h
Fix bug #6315: counters in insets that don't produce output have ghost values.
[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 "Dimension.h"
18
19 #include <boost/scoped_ptr.hpp>
20
21 namespace lyx {
22
23 class RenderPreview;
24
25 namespace graphics {
26         class PreviewLoader;
27 }
28
29 /// An inset with an instant preview
30 class InsetPreview : public InsetText {
31         
32 public:
33         ///
34         InsetPreview(Buffer *);
35         ///
36         ~InsetPreview();
37         ///
38         InsetPreview(InsetPreview const & other);
39
40         /// \name Methods inherited from Inset class
41         //@{
42         Inset * clone() const { return new InsetPreview(*this); }
43
44         bool neverIndent() const { return true; }
45         
46         InsetCode lyxCode() const { return PREVIEW_CODE; }
47         
48         docstring name() const { return from_ascii("Preview"); }
49         
50         bool descendable(BufferView const & /*bv*/) const { return true; }
51
52         docstring contextMenu(BufferView const &, int, int) const
53                 { return from_ascii("context-preview"); }
54
55         void metrics(MetricsInfo & mi, Dimension & dim) const;
56
57         Inset * editXY(Cursor & cur, int x, int y);
58
59         void draw(PainterInfo & pi, int x, int y) const;
60
61         void addPreview(DocIterator const & inset_pos,
62                 graphics::PreviewLoader & ploader) const;
63
64         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
65
66         void write(std::ostream & os) const;
67
68         void edit(Cursor & cur, bool front, EntryDirection entry_from);
69         //@}
70         
71 protected:
72         /// Retrieves the preview state. Returns true if preview
73         /// is enabled and the preview image is availabled.
74         bool previewState(BufferView * bv) const;
75         /// Recreates the preview if preview is enabled.
76         void reloadPreview(DocIterator const & pos) const;
77         /// Prepare the preview if preview is enabled.
78         void preparePreview(DocIterator const & pos) const;
79
80         ///
81         boost::scoped_ptr<RenderPreview> preview_;
82         ///
83         mutable bool use_preview_;
84
85 private:
86         ///
87         mutable Dimension dim_;
88 };
89
90
91 } // namespace lyx
92
93
94 #endif
95