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"
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/signals/trackable.hpp>
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.
43 TempName(TempName const &);
45 TempName & operator=(TempName const &);
46 support::FileName operator()() const;
48 support::TempFile * tempfile_;
51 } // namespace external
54 /// hold parameters settable from the GUI
55 class InsetExternalParams {
57 InsetExternalParams();
59 void write(Buffer const &, std::ostream &) const;
60 bool read(Buffer const &, Lexer &);
62 /// The name of the tempfile used for manipulations.
63 support::FileName tempname() const { return tempname_(); }
65 /// The template currently in use.
66 void settemplate(std::string const &);
67 std::string const & templatename() const { return templatename_; }
69 /// The external file.
70 support::DocFileName filename;
71 /// If the inset is to be displayed by LyX.
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;
78 external::ClipData clipdata;
79 external::ExtraData extradata;
80 external::ResizeData resizedata;
81 external::RotationData rotationdata;
83 /** if \c true, simply output the filename, maybe wrapped in a
84 * box, rather than generate and display the image etc.
89 external::TempName tempname_;
90 std::string templatename_;
97 class InsetExternal : public Inset, public boost::signals::trackable
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 &);
103 InsetExternal(Buffer *);
107 static void string2params(std::string const &, Buffer const &,
108 InsetExternalParams &);
110 static std::string params2string(InsetExternalParams const &,
113 InsetExternalParams const & params() const;
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;
121 std::string contextMenuName() const;
123 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
125 bool clickable(int, int) const { return true; }
127 void addToToc(DocIterator const & di, bool output_active,
128 UpdateType utype) const;
131 InsetExternal(InsetExternal const &);
133 InsetCode lyxCode() const { return EXTERNAL_CODE; }
135 bool hasSettings() const { return true; }
137 void metrics(MetricsInfo &, Dimension &) const;
139 void draw(PainterInfo & pi, int x, int y) const;
141 void write(std::ostream &) const;
143 void read(Lexer & lex);
145 int plaintext(odocstringstream & ods, OutputParams const & op,
146 size_t max_length = INT_MAX) const;
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;
155 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
157 bool showInsetDialog(BufferView * bv) const;
159 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
161 void doDispatch(Cursor & cur, FuncRequest & cmd);
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.
167 void statusChanged() const;
168 /** Slot receiving a signal that the external file has changed
169 * and the preview should be regenerated.
171 void fileChanged() const;
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_;
183 #endif // INSET_EXTERNAL_H