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