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 explicit 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;
124 InsetCode lyxCode() const { return EXTERNAL_CODE; }
126 bool hasSettings() const { return true; }
129 int topOffset(BufferView const *) const { return 0; }
131 int bottomOffset(BufferView const *) const { return 0; }
133 int leftOffset(BufferView const *) const { return 0; }
135 int rightOffset(BufferView const *) const { return 0; }
138 void metrics(MetricsInfo &, Dimension &) const;
140 void draw(PainterInfo & pi, int x, int y) const;
142 void write(std::ostream &) const;
144 void read(Lexer & lex);
146 int plaintext(odocstringstream & ods, OutputParams const & op,
147 size_t max_length = INT_MAX) const;
149 void generateXML(XMLStream &, OutputParams const &, std::string const &) const;
151 void docbook(XMLStream &, OutputParams const &) const;
152 /// For now, this does nothing. Someone who knows about this
153 /// should see what needs doing for XHTML output.
154 docstring xhtml(XMLStream &, OutputParams const &) const;
155 /// Update needed features for this inset.
156 void validate(LaTeXFeatures & features) const;
158 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
160 bool showInsetDialog(BufferView * bv) const;
162 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
164 void doDispatch(Cursor & cur, FuncRequest & cmd);
166 Inset * clone() const { return new InsetExternal(*this); }
167 /** Slot receiving a signal that the external file has changed
168 * and the preview should be regenerated.
170 void fileChanged() const;
174 InsetExternal(InsetExternal const &);
176 /// Is this inset using (instant or graphics) preview?
177 bool isPreviewed() const;
178 /// Do we have the right renderer (button, graphic or monitored preview)?
179 bool isRendererValid() const;
181 /// The current params
182 InsetExternalParams params_;
183 /// The thing that actually draws the image on LyX's screen.
184 mutable unique_ptr<RenderBase> renderer_;
185 /// changes color of the button when mouse enters/leaves this inset
186 mutable std::map<BufferView const *, bool> mouse_hover_;
191 #endif // INSET_EXTERNAL_H