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"
17 #include "EmbeddedFiles.h"
19 #include "support/FileName.h"
20 #include "support/Translator.h"
22 #include <boost/scoped_ptr.hpp>
23 #include <boost/signals/trackable.hpp>
25 #include "MailInset.h"
28 /** No two InsetExternalParams variables can have the same temporary file.
29 * This class has copy-semantics but the copy constructor
30 * and assignment operator simply call the default constructor.
31 * Use of this class enables us to use the compiler-generated
32 * copy constructor and assignment operator for the
33 * InsetExternalParams class.
42 TempName(TempName const &);
44 TempName & operator=(TempName const &);
45 support::FileName const & operator()() const { return tempname_; }
47 support::FileName tempname_;
50 /// How is the image to be displayed on the LyX screen?
61 /// The translator between the Display enum and corresponding lyx string.
62 Translator<DisplayType, std::string> const & displayTranslator();
64 } // namespace external
67 /// hold parameters settable from the GUI
68 class InsetExternalParams {
70 InsetExternalParams();
72 void write(Buffer const &, std::ostream &) const;
73 bool read(Buffer const &, Lexer &);
75 /// The name of the tempfile used for manipulations.
76 support::FileName const & tempname() const { return tempname_(); }
78 /// The template currently in use.
79 void settemplate(std::string const &);
80 std::string const & templatename() const { return templatename_; }
82 /// The external file.
83 EmbeddedFile filename;
84 /// How the inset is to be displayed by LyX.
85 external::DisplayType display;
86 /// The scale of the displayed graphic (if shown).
87 unsigned int lyxscale;
89 external::ClipData clipdata;
90 external::ExtraData extradata;
91 external::ResizeData resizedata;
92 external::RotationData rotationdata;
94 /** if \c true, simply output the filename, maybe wrapped in a
95 * box, rather than generate and display the image etc.
100 external::TempName tempname_;
101 std::string templatename_;
108 class InsetExternal : public Inset, public boost::signals::trackable
115 void setBuffer(Buffer & buffer);
117 InsetCode lyxCode() const { return EXTERNAL_CODE; }
119 EDITABLE editable() const { return IS_EDITABLE; }
122 void metrics(MetricsInfo &, Dimension &) const;
124 void draw(PainterInfo & pi, int x, int y) const;
126 void write(std::ostream &) const;
128 void read(Lexer & lex);
130 /// \returns the number of rows (\n's) of generated code.
131 int latex(odocstream &, OutputParams const &) const;
133 int plaintext(odocstream &, OutputParams const &) const;
135 int docbook(odocstream &, 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 &);
145 void addPreview(graphics::PreviewLoader &) const;
147 void edit(Cursor & cur, bool front, EntryDirection entry_from);
149 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
150 /// external file can be embedded
151 void registerEmbeddedFiles(EmbeddedFileList &) const;
153 void updateEmbeddedFile(EmbeddedFile const &);
156 InsetExternal(InsetExternal const &);
158 void doDispatch(Cursor & cur, FuncRequest & cmd);
161 Inset * clone() const { return new InsetExternal(*this); }
163 /** This method is connected to the graphics loader, so we are
164 * informed when the image has been loaded.
166 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_;
180 class InsetExternalMailer : public MailInset {
183 InsetExternalMailer(InsetExternal & inset);
185 virtual Inset & inset() const { return inset_; }
187 virtual std::string const & name() const { return name_; }
189 virtual std::string const inset2string(Buffer const &) const;
191 static void string2params(std::string const &, Buffer const &,
192 InsetExternalParams &);
194 static std::string const params2string(InsetExternalParams const &,
198 static std::string const name_;
200 InsetExternal & inset_;