3 * \file InsetExternal.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Asger Alstrup Nielsen
9 * Full author contact details are available in file CREDITS.
12 #ifndef INSET_EXTERNAL_H
13 #define INSET_EXTERNAL_H
17 #include "ExternalTemplate.h"
19 #include "support/FileName.h"
20 #include "support/unique_ptr.h"
27 /** No two InsetExternalParams variables can have the same temporary file.
28 * This class has copy-semantics but the copy constructor
29 * and assignment operator simply call the default constructor.
30 * Use of this class enables us to use the compiler-generated
31 * copy constructor and assignment operator for the
32 * InsetExternalParams class.
37 TempName(TempName const &);
39 TempName & operator=(TempName const &);
40 support::FileName operator()() const;
42 support::FileName tempname_;
45 } // namespace external
48 /// hold parameters settable from the GUI
49 class InsetExternalParams {
51 InsetExternalParams();
53 void write(Buffer const &, std::ostream &) const;
54 bool read(Buffer const &, Lexer &);
56 /// The name of the tempfile used for manipulations.
57 support::FileName tempname() const { return tempname_(); }
59 /// The template currently in use.
60 void settemplate(std::string const &);
61 std::string const & templatename() const { return templatename_; }
63 /// The external file.
64 support::DocFileName filename;
65 /// If the inset is to be displayed by LyX.
67 /// If the inset is to use the preview mechanism.
68 PreviewMode preview_mode;
69 /// The scale of the displayed graphic (if shown).
70 unsigned int lyxscale;
72 external::ClipData clipdata;
73 external::ExtraData extradata;
74 external::ResizeData resizedata;
75 external::RotationData rotationdata;
77 /** if \c true, simply output the filename, maybe wrapped in a
78 * box, rather than generate and display the image etc.
83 external::TempName tempname_;
84 std::string templatename_;
91 class InsetExternal : public Inset
93 // Disable assignment operator, since it is not used, and it is too
94 // complicated to implement it consistently with the copy constructor
95 InsetExternal & operator=(InsetExternal const &);
97 InsetExternal(Buffer *);
101 static void string2params(std::string const &, Buffer const &,
102 InsetExternalParams &);
104 static std::string params2string(InsetExternalParams const &,
107 InsetExternalParams const & params() const;
109 void setParams(InsetExternalParams const &);
110 /// Update not loaded previews
111 void updatePreview() const;
112 /// \returns the number of rows (\n's) of generated code.
113 void latex(otexstream &, OutputParams const &) const;
115 std::string contextMenuName() const;
117 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
119 bool clickable(BufferView const &, int, int) const { return true; }
121 void addToToc(DocIterator const & di, bool output_active,
122 UpdateType utype, TocBackend & backend) const;
125 InsetExternal(InsetExternal const &);
127 InsetCode lyxCode() const { return EXTERNAL_CODE; }
129 bool hasSettings() const { return true; }
131 void metrics(MetricsInfo &, Dimension &) const;
133 void draw(PainterInfo & pi, int x, int y) const;
135 void write(std::ostream &) const;
137 void read(Lexer & lex);
139 int plaintext(odocstringstream & ods, OutputParams const & op,
140 size_t max_length = INT_MAX) const;
142 int docbook(odocstream &, OutputParams const &) const;
143 /// For now, this does nothing. Someone who knows about this
144 /// should see what needs doing for XHTML output.
145 docstring xhtml(XHTMLStream &, OutputParams const &) const;
146 /// Update needed features for this inset.
147 void validate(LaTeXFeatures & features) const;
149 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
151 bool showInsetDialog(BufferView * bv) const;
153 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
155 void doDispatch(Cursor & cur, FuncRequest & cmd);
157 Inset * clone() const { return new InsetExternal(*this); }
158 /** This method is connected to the graphics loader, so we are
159 * informed when the image has been loaded.
161 void statusChanged() const;
162 /** Slot receiving a signal that the external file has changed
163 * and the preview should be regenerated.
165 void fileChanged() const;
166 /// Is this inset using (instant or graphics) preview?
167 bool isPreviewed() const;
168 /// Do we have the right renderer (button, graphic or monitored preview)?
169 bool isRendererValid() const;
171 /// The current params
172 InsetExternalParams params_;
173 /// The thing that actually draws the image on LyX's screen.
174 mutable unique_ptr<RenderBase> renderer_;
175 /// changes color of the button when mouse enters/leaves this inset
176 mutable std::map<BufferView const *, bool> mouse_hover_;
181 #endif // INSET_EXTERNAL_H