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 "graphics/GraphicsTypes.h"
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/signals/trackable.hpp>
27 class InsetExternal : public Inset, public boost::signals::trackable {
29 /// hold parameters settable from the GUI
31 // Params(string const & f = string(),
32 // string const & p = string(),
33 // ExternalTemplate const & t = ExternalTemplate())
34 Params() : display(grfx::NoDisplay), lyxscale(100) {}
37 /// the parameters of the current choice
39 /// the current template used
40 ExternalTemplate templ;
41 /// how the inset is displayed by LyX
42 grfx::DisplayType display;
43 /// The scale of the displayed graphic (If shown).
44 unsigned int lyxscale;
49 InsetExternal(InsetExternal const &);
51 virtual ~InsetExternal();
53 virtual dispatch_result localDispatch(FuncRequest const & cmd);
54 /** Would not be needed if editExternal were dispatched properly from
55 * the frontends rather than being invoked directly.
57 virtual void cache(BufferView *) const;
59 void metrics(MetricsInfo &, Dimension &) const;
61 void draw(PainterInfo & pi, int x, int y) const;
62 /// what appears in the minibuffer when opening
63 virtual string const editMessage() const;
65 virtual EDITABLE editable() const { return IS_EDITABLE; }
67 virtual void write(Buffer const *, std::ostream &) const;
69 virtual void read(Buffer const *, LyXLex & lex);
71 /** returns the number of rows (\n's) of generated tex code.
72 fragile == true means, that the inset should take care about
73 fragile commands by adding a \protect before.
74 If the free_spc (freespacing) variable is set, then this inset
75 is in a free-spacing paragraph.
77 virtual int latex(Buffer const *, std::ostream &,
78 LatexRunParams const &) const;
79 /// write ASCII output to the ostream
80 virtual int ascii(Buffer const *, std::ostream &, int linelen) const;
81 /// write LinuxDoc output to the ostream
82 virtual int linuxdoc(Buffer const *, std::ostream &) const;
83 /// write DocBook output to the ostream
84 virtual int docbook(Buffer const *, std::ostream &, bool mixcont) const;
86 /// Updates needed features for this inset.
87 virtual void validate(LaTeXFeatures & features) const;
89 /// returns LyX code associated with the inset. Used for TOC, ...)
90 virtual Inset::Code lyxCode() const { return EXTERNAL_CODE; }
93 virtual Inset * clone() const;
95 /// returns the text of the button
96 virtual string const getScreenLabel(Buffer const *) const;
98 // The following public members are used from the frontends code
100 /// Set the inset parameters.
101 virtual void setParams(Params const &, string const & filepath);
104 void updateExternal() const;
106 /** update the file represented by the template.
107 If \param external_in_tmpdir == true, then the generated file is
108 place in the buffer's temporary directory.
110 void updateExternal(string const &, Buffer const *,
111 bool external_in_tmpdir) const;
113 /// edit file of this template
114 void editExternal() const;
116 /// return a copy of our current params
117 Params const & params() const;
120 /** This method is connected to the graphics loader, so we are
121 * informed when the image has been loaded.
123 void statusChanged();
125 /** Write the output for a specific file format
126 and generate any external data files.
127 If \param external_in_tmpdir == true, then the generated file is
128 place in the buffer's temporary directory.
130 int write(string const & format, Buffer const *, std::ostream &,
131 bool external_in_tmpdir = false) const;
133 /// Substitute meta-variables in this string
134 string const doSubstitution(Buffer const *, string const & s) const;
136 /// the current params
140 mutable string tempname_;
142 /// The thing that actually draws the image on LyX's screen.
143 boost::scoped_ptr<GraphicInset> const graphic_;
147 #include "mailinset.h"
149 class InsetExternalMailer : public MailInset {
152 InsetExternalMailer(InsetExternal & inset);
154 virtual InsetBase & inset() const { return inset_; }
156 virtual string const & name() const { return name_; }
158 virtual string const inset2string() const;
160 static void string2params(string const &, InsetExternal::Params &);
162 static string const params2string(InsetExternal::Params const &);
165 static string const name_;
167 InsetExternal & inset_;