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>
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 /// How is the image to be displayed on the LyX screen?
59 /// The translator between the Display enum and corresponding lyx string.
60 Translator<DisplayType, std::string> const & displayTranslator();
62 } // namespace external
65 /// hold parameters settable from the GUI
66 class InsetExternalParams {
68 InsetExternalParams();
70 void write(Buffer const &, std::ostream &) const;
71 bool read(Buffer const &, Lexer &);
73 /// The name of the tempfile used for manipulations.
74 support::FileName const & tempname() const { return tempname_(); }
76 /// The template currently in use.
77 void settemplate(std::string const &);
78 std::string const & templatename() const { return templatename_; }
80 /// The external file.
81 EmbeddedFile filename;
82 /// How the inset is to be displayed by LyX.
83 external::DisplayType display;
84 /// The scale of the displayed graphic (if shown).
85 unsigned int lyxscale;
87 external::ClipData clipdata;
88 external::ExtraData extradata;
89 external::ResizeData resizedata;
90 external::RotationData rotationdata;
92 /** if \c true, simply output the filename, maybe wrapped in a
93 * box, rather than generate and display the image etc.
98 external::TempName tempname_;
99 std::string templatename_;
106 class InsetExternal : public Inset, public boost::signals::trackable
109 InsetExternal(Buffer &);
113 static void string2params(std::string const &, Buffer const &,
114 InsetExternalParams &);
116 static std::string params2string(InsetExternalParams const &,
119 InsetExternalParams const & params() const;
121 void setParams(InsetExternalParams const &);
123 void setBuffer(Buffer & buffer);
124 /// \returns the number of rows (\n's) of generated code.
125 int latex(odocstream &, OutputParams const &) const;
129 InsetExternal(InsetExternal const &);
131 InsetCode lyxCode() const { return EXTERNAL_CODE; }
133 EDITABLE editable() const { return IS_EDITABLE; }
135 void metrics(MetricsInfo &, Dimension &) const;
137 void draw(PainterInfo & pi, int x, int y) const;
139 void write(std::ostream &) const;
141 void read(Lexer & lex);
143 int plaintext(odocstream &, OutputParams const &) const;
145 int docbook(odocstream &, OutputParams const &) const;
146 /// Update needed features for this inset.
147 void validate(LaTeXFeatures & features) const;
149 void addPreview(graphics::PreviewLoader &) const;
151 void edit(Cursor & cur, bool front, EntryDirection entry_from);
153 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
154 /// external file can be embedded
155 void registerEmbeddedFiles(EmbeddedFileList &) const;
157 void updateEmbeddedFile(EmbeddedFile const &);
159 void doDispatch(Cursor & cur, FuncRequest & cmd);
161 Inset * clone() const { return new InsetExternal(*this); }
162 /** This method is connected to the graphics loader, so we are
163 * informed when the image has been loaded.
165 void statusChanged() const;
166 /** Slot receiving a signal that the external file has changed
167 * and the preview should be regenerated.
169 void fileChanged() const;
171 /// The current params
172 InsetExternalParams params_;
173 /// The thing that actually draws the image on LyX's screen.
174 boost::scoped_ptr<RenderBase> renderer_;
179 #endif // INSET_EXTERNAL_H