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 "graphics/GraphicsTypes.h"
19 #include "support/filename.h"
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/signals/trackable.hpp>
28 class InsetExternal : public InsetOld, public boost::signals::trackable
30 /** No two Params variables can have the same temporary file.
31 * This struct has copy-semantics but the copy constructor
32 * and assignment operator simply call the default constructor.
33 * Use of this struct enables us to use the compiler-generated
34 * copy constructor and assignment operator for the Params struct.
38 TempName(TempName const &);
40 TempName & operator=(TempName const &);
41 std::string const & operator()() const { return tempname_; }
43 std::string tempname_;
47 /// hold parameters settable from the GUI
51 void write(Buffer const &, std::ostream &) const;
52 bool read(Buffer const &, LyXLex &);
54 /// The name of the tempfile used for manipulations.
55 std::string const & tempname() const { return tempname_(); }
57 /// the current template used
58 void settemplate(std::string const &);
59 std::string const & templatename() const { return templatename_; }
62 lyx::support::FileName filename;
63 /// how the inset is displayed by LyX
64 lyx::graphics::DisplayType display;
65 /// The scale of the displayed graphic (If shown).
66 unsigned int lyxscale;
70 std::string templatename_;
75 InsetExternal(InsetExternal const &);
77 virtual ~InsetExternal();
79 virtual dispatch_result localDispatch(FuncRequest const & cmd);
81 void metrics(MetricsInfo &, Dimension &) const;
83 void draw(PainterInfo & pi, int x, int y) const;
85 virtual EDITABLE editable() const { return IS_EDITABLE; }
87 virtual void write(Buffer const &, std::ostream &) const;
89 virtual void read(Buffer const &, LyXLex & lex);
91 /** returns the number of rows (\n's) of generated tex code.
92 fragile == true means, that the inset should take care about
93 fragile commands by adding a \protect before.
94 If the free_spc (freespacing) variable is set, then this inset
95 is in a free-spacing paragraph.
97 virtual int latex(Buffer const &, std::ostream &,
98 LatexRunParams const &) const;
99 /// write ASCII output to the ostream
100 virtual int ascii(Buffer const &, std::ostream &, int linelen) const;
101 /// write LinuxDoc output to the ostream
102 virtual int linuxdoc(Buffer const &, std::ostream &) const;
103 /// write DocBook output to the ostream
104 virtual int docbook(Buffer const &, std::ostream &, bool mixcont) const;
106 /// Updates needed features for this inset.
107 virtual void validate(LaTeXFeatures & features) const;
109 /// returns LyX code associated with the inset. Used for TOC, ...)
110 virtual InsetOld::Code lyxCode() const { return EXTERNAL_CODE; }
113 virtual std::auto_ptr<InsetBase> clone() const;
115 /// return a copy of our current params
116 Params const & params() const;
118 /// Set the inset parameters.
119 virtual void setParams(Params const &, Buffer const &);
121 /** update the file represented by the template.
122 If \param external_in_tmpdir == true, then the generated file is
123 place in the buffer's temporary directory.
125 void updateExternal(std::string const &, Buffer const &,
126 bool external_in_tmpdir) const;
129 /** This method is connected to the graphics loader, so we are
130 * informed when the image has been loaded.
132 void statusChanged();
134 /** Write the output for a specific file format
135 and generate any external data files.
136 If \param external_in_tmpdir == true, then the generated file is
137 place in the buffer's temporary directory.
139 int write(std::string const & format, Buffer const &, std::ostream &,
140 bool external_in_tmpdir = false) const;
142 /// the current params
145 /// The thing that actually draws the image on LyX's screen.
146 boost::scoped_ptr<RenderInset> renderer_;
150 #include "mailinset.h"
152 class InsetExternalMailer : public MailInset {
155 InsetExternalMailer(InsetExternal & inset);
157 virtual InsetBase & inset() const { return inset_; }
159 virtual std::string const & name() const { return name_; }
161 virtual std::string const inset2string(Buffer const &) const;
163 static void string2params(std::string const &, Buffer const &,
164 InsetExternal::Params &);
166 static std::string const params2string(InsetExternal::Params const &,
170 static std::string const name_;
172 InsetExternal & inset_;