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
16 #include "ExternalTemplate.h"
17 #include "ExternalTransforms.h"
19 #include "support/FileName.h"
20 #include "support/Translator.h"
22 #include <boost/scoped_ptr.hpp>
23 #include <boost/signals/trackable.hpp>
26 /** No two InsetExternalParams variables can have the same temporary file.
27 * This class has copy-semantics but the copy constructor
28 * and assignment operator simply call the default constructor.
29 * Use of this class enables us to use the compiler-generated
30 * copy constructor and assignment operator for the
31 * InsetExternalParams class.
40 TempName(TempName const &);
42 TempName & operator=(TempName const &);
43 support::FileName const & operator()() const { return tempname_; }
45 support::FileName tempname_;
48 } // namespace external
51 /// hold parameters settable from the GUI
52 class InsetExternalParams {
54 InsetExternalParams();
56 void write(Buffer const &, std::ostream &) const;
57 bool read(Buffer const &, Lexer &);
59 /// The name of the tempfile used for manipulations.
60 support::FileName const & tempname() const { return tempname_(); }
62 /// The template currently in use.
63 void settemplate(std::string const &);
64 std::string const & templatename() const { return templatename_; }
66 /// The external file.
67 support::DocFileName filename;
68 /// If the inset is to be displayed by LyX.
70 /// If the inset is to use the preview mechanism.
71 PreviewMode preview_mode;
72 /// The scale of the displayed graphic (if shown).
73 unsigned int lyxscale;
75 external::ClipData clipdata;
76 external::ExtraData extradata;
77 external::ResizeData resizedata;
78 external::RotationData rotationdata;
80 /** if \c true, simply output the filename, maybe wrapped in a
81 * box, rather than generate and display the image etc.
86 external::TempName tempname_;
87 std::string templatename_;
94 class InsetExternal : public Inset, public boost::signals::trackable
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();
112 /// \returns the number of rows (\n's) of generated code.
113 int latex(odocstream &, OutputParams const &) const;
115 docstring contextMenu(BufferView const & bv, int x, int y) const;
119 InsetExternal(InsetExternal const &);
121 InsetCode lyxCode() const { return EXTERNAL_CODE; }
123 bool hasSettings() const { return true; }
125 void metrics(MetricsInfo &, Dimension &) const;
127 void draw(PainterInfo & pi, int x, int y) const;
129 void write(std::ostream &) const;
131 void read(Lexer & lex);
133 int plaintext(odocstream &, OutputParams const &) const;
135 int docbook(odocstream &, OutputParams const &) const;
136 /// For now, this does nothing. Someone who knows about this
137 /// should see what needs doing for XHTML output.
138 docstring xhtml(XHTMLStream &, OutputParams const &) const;
139 /// Update needed features for this inset.
140 void validate(LaTeXFeatures & features) const;
142 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
144 bool showInsetDialog(BufferView * bv) const;
146 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
148 void doDispatch(Cursor & cur, FuncRequest & cmd);
150 Inset * clone() const { return new InsetExternal(*this); }
151 /** This method is connected to the graphics loader, so we are
152 * informed when the image has been loaded.
154 void statusChanged() const;
155 /** Slot receiving a signal that the external file has changed
156 * and the preview should be regenerated.
158 void fileChanged() const;
160 /// The current params
161 InsetExternalParams params_;
162 /// The thing that actually draws the image on LyX's screen.
163 boost::scoped_ptr<RenderBase> renderer_;
168 #endif // INSET_EXTERNAL_H