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 "ExternalTransforms.h"
18 #include "support/filename.h"
19 #include "support/translator.h"
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/signals/trackable.hpp>
24 #include "mailinset.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.
41 TempName(TempName const &);
43 TempName & operator=(TempName const &);
44 std::string const & operator()() const { return tempname_; }
46 std::string tempname_;
49 /// How is the image to be displayed on the LyX screen?
60 /// The translator between the Display enum and corresponding lyx string.
61 Translator<DisplayType, std::string> const & displayTranslator();
63 } // namespace external
66 /// hold parameters settable from the GUI
67 class InsetExternalParams {
69 InsetExternalParams();
71 void write(Buffer const &, std::ostream &) const;
72 bool read(Buffer const &, LyXLex &);
74 /// The name of the tempfile used for manipulations.
75 std::string const & tempname() const { return tempname_(); }
77 /// The template currently in use.
78 void settemplate(std::string const &);
79 std::string const & templatename() const { return templatename_; }
81 /// The external file.
82 support::DocFileName filename;
83 /// How the inset is to be displayed by LyX.
84 external::DisplayType display;
85 /// The scale of the displayed graphic (if shown).
86 unsigned int lyxscale;
88 external::ClipData clipdata;
89 external::ExtraData extradata;
90 external::ResizeData resizedata;
91 external::RotationData rotationdata;
93 /** if \c true, simply output the filename, maybe wrapped in a
94 * box, rather than generate and display the image etc.
99 external::TempName tempname_;
100 std::string templatename_;
107 class InsetExternal : public InsetOld, public boost::signals::trackable
112 virtual ~InsetExternal();
114 virtual InsetBase::Code lyxCode() const { return EXTERNAL_CODE; }
116 virtual EDITABLE editable() const { return IS_EDITABLE; }
119 void metrics(MetricsInfo &, Dimension &) const;
121 void draw(PainterInfo & pi, int x, int y) const;
123 virtual void write(Buffer const &, std::ostream &) const;
125 virtual void read(Buffer const &, LyXLex & lex);
127 /// \returns the number of rows (\n's) of generated code.
128 virtual int latex(Buffer const &, odocstream &,
129 OutputParams const &) const;
131 virtual int plaintext(Buffer const &, odocstream &,
132 OutputParams const &) const;
134 virtual int docbook(Buffer const &, odocstream &,
135 OutputParams const &) const;
137 /// Update needed features for this inset.
138 virtual void validate(LaTeXFeatures & features) const;
141 InsetExternalParams const & params() const;
143 void setParams(InsetExternalParams const &, Buffer const &);
145 void addPreview(graphics::PreviewLoader &) const;
147 void edit(LCursor & cur, bool left);
149 bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
152 InsetExternal(InsetExternal const &);
154 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
156 virtual std::auto_ptr<InsetBase> doClone() const;
158 /** This method is connected to the graphics loader, so we are
159 * informed when the image has been loaded.
161 void statusChanged() const;
163 /** Slot receiving a signal that the external file has changed
164 * and the preview should be regenerated.
166 void fileChanged() const;
168 /// The current params
169 InsetExternalParams params_;
170 /// The thing that actually draws the image on LyX's screen.
171 boost::scoped_ptr<RenderBase> renderer_;
175 class InsetExternalMailer : public MailInset {
178 InsetExternalMailer(InsetExternal & inset);
180 virtual InsetBase & inset() const { return inset_; }
182 virtual std::string const & name() const { return name_; }
184 virtual std::string const inset2string(Buffer const &) const;
186 static void string2params(std::string const &, Buffer const &,
187 InsetExternalParams &);
189 static std::string const params2string(InsetExternalParams const &,
193 static std::string const name_;
195 InsetExternal & inset_;