]> git.lyx.org Git - lyx.git/blob - src/insets/InsetExternal.h
Fix bug #6315: counters in insets that don't produce output have ghost values.
[lyx.git] / src / insets / InsetExternal.h
1 // -*- C++ -*-
2 /**
3  * \file InsetExternal.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup Nielsen
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSET_EXTERNAL_H
13 #define INSET_EXTERNAL_H
14
15 #include "Inset.h"
16
17 #include "ExternalTemplate.h"
18
19 #include "support/FileName.h"
20
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/signals/trackable.hpp>
23
24
25 /** No two InsetExternalParams variables can have the same temporary file.
26  *  This class has copy-semantics but the copy constructor
27  *  and assignment operator simply call the default constructor.
28  *  Use of this class enables us to use the compiler-generated
29  *  copy constructor and assignment operator for the
30  *  InsetExternalParams class.
31  */
32 namespace lyx {
33
34 namespace external {
35
36 class TempName {
37 public:
38         TempName();
39         TempName(TempName const &);
40         ~TempName();
41         TempName & operator=(TempName const &);
42         support::FileName const & operator()() const { return tempname_; }
43 private:
44         support::FileName tempname_;
45 };
46
47 } // namespace external
48
49
50 /// hold parameters settable from the GUI
51 class InsetExternalParams {
52 public:
53         InsetExternalParams();
54
55         void write(Buffer const &, std::ostream &) const;
56         bool read(Buffer const &, Lexer &);
57
58         /// The name of the tempfile used for manipulations.
59         support::FileName const & tempname() const { return tempname_(); }
60
61         /// The template currently in use.
62         void settemplate(std::string const &);
63         std::string const & templatename() const { return templatename_; }
64
65         /// The external file.
66         support::DocFileName filename;
67         /// If the inset is to be displayed by LyX.
68         bool display;
69         /// If the inset is to use the preview mechanism.
70         PreviewMode preview_mode;
71         /// The scale of the displayed graphic (if shown).
72         unsigned int lyxscale;
73
74         external::ClipData     clipdata;
75         external::ExtraData    extradata;
76         external::ResizeData   resizedata;
77         external::RotationData rotationdata;
78
79         /** if \c true, simply output the filename, maybe wrapped in a
80          *  box, rather than generate and display the image etc.
81          */
82         bool draft;
83
84 private:
85         external::TempName tempname_;
86         std::string templatename_;
87 };
88
89
90 class RenderBase;
91
92 ///
93 class InsetExternal : public Inset, public boost::signals::trackable
94 {
95 public:
96         InsetExternal(Buffer *);
97         ///
98         ~InsetExternal();
99         ///
100         static void string2params(std::string const &, Buffer const &,
101                                   InsetExternalParams &);
102         ///
103         static std::string params2string(InsetExternalParams const &,
104                                                Buffer const &);
105         ///
106         InsetExternalParams const & params() const;
107         ///
108         void setParams(InsetExternalParams const &);
109         /// Update not loaded previews
110         void updatePreview();
111         /// \returns the number of rows (\n's) of generated code.
112         int latex(odocstream &, OutputParams const &) const;
113         ///
114         docstring contextMenu(BufferView const & bv, int x, int y) const;
115         ///
116         bool setMouseHover(BufferView const * bv, bool mouse_hover);
117         ///
118         bool clickable(int, int) const { return true; }
119 private:
120         ///
121         InsetExternal(InsetExternal const &);
122         ///
123         InsetCode lyxCode() const { return EXTERNAL_CODE; }
124         ///
125         bool hasSettings() const { return true; }
126         ///
127         void metrics(MetricsInfo &, Dimension &) const;
128         ///
129         void draw(PainterInfo & pi, int x, int y) const;
130         ///
131         void write(std::ostream &) const;
132         ///
133         void read(Lexer & lex);
134         ///
135         int plaintext(odocstream &, OutputParams const &) const;
136         ///
137         int docbook(odocstream &, OutputParams const &) const;
138         /// For now, this does nothing. Someone who knows about this
139         /// should see what needs doing for XHTML output.
140         docstring xhtml(XHTMLStream &, OutputParams const &) const;
141         /// Update needed features for this inset.
142         void validate(LaTeXFeatures & features) const;
143         ///
144         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
145         ///
146         bool showInsetDialog(BufferView * bv) const;
147         ///
148         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
149         ///
150         void doDispatch(Cursor & cur, FuncRequest & cmd);
151         ///
152         Inset * clone() const { return new InsetExternal(*this); }
153         /** This method is connected to the graphics loader, so we are
154          *  informed when the image has been loaded.
155          */
156         void statusChanged() const;
157         /** Slot receiving a signal that the external file has changed
158          *  and the preview should be regenerated.
159          */
160         void fileChanged() const;
161
162         /// The current params
163         InsetExternalParams params_;
164         /// The thing that actually draws the image on LyX's screen.
165         boost::scoped_ptr<RenderBase> renderer_;
166         /// changes color of the button when mouse enters/leaves this inset
167         mutable std::map<BufferView const *, bool> mouse_hover_;
168 };
169
170 } // namespace lyx
171
172 #endif // INSET_EXTERNAL_H