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>
25 /** No two InsetExternalParams variables can have the same temporary file.
26 * This class has copy-semantics but the copy constructor
27 * and assignment operator simply call the default constructor.
28 * Use of this class enables us to use the compiler-generated
29 * copy constructor and assignment operator for the
30 * InsetExternalParams class.
39 TempName(TempName const &);
41 TempName & operator=(TempName const &);
42 support::FileName const & operator()() const { return tempname_; }
44 support::FileName tempname_;
47 /// How is the image to be displayed on the LyX screen?
58 /// The translator between the Display enum and corresponding lyx string.
59 Translator<DisplayType, std::string> const & displayTranslator();
61 } // namespace external
64 /// hold parameters settable from the GUI
65 class InsetExternalParams {
67 InsetExternalParams();
69 void write(Buffer const &, std::ostream &) const;
70 bool read(Buffer const &, Lexer &);
72 /// The name of the tempfile used for manipulations.
73 support::FileName const & tempname() const { return tempname_(); }
75 /// The template currently in use.
76 void settemplate(std::string const &);
77 std::string const & templatename() const { return templatename_; }
79 /// The external file.
80 support::DocFileName filename;
81 /// How the inset is to be displayed by LyX.
82 external::DisplayType display;
83 /// The scale of the displayed graphic (if shown).
84 unsigned int lyxscale;
86 external::ClipData clipdata;
87 external::ExtraData extradata;
88 external::ResizeData resizedata;
89 external::RotationData rotationdata;
91 /** if \c true, simply output the filename, maybe wrapped in a
92 * box, rather than generate and display the image etc.
97 external::TempName tempname_;
98 std::string templatename_;
105 class InsetExternal : public Inset, public boost::signals::trackable
108 InsetExternal(Buffer &);
112 static void string2params(std::string const &, Buffer const &,
113 InsetExternalParams &);
115 static std::string params2string(InsetExternalParams const &,
118 InsetExternalParams const & params() const;
120 void setParams(InsetExternalParams const &);
121 /// \returns the number of rows (\n's) of generated code.
122 int latex(odocstream &, OutputParams const &) const;
126 InsetExternal(InsetExternal const &);
128 InsetCode lyxCode() const { return EXTERNAL_CODE; }
130 EDITABLE editable() const { return IS_EDITABLE; }
132 void metrics(MetricsInfo &, Dimension &) const;
134 void draw(PainterInfo & pi, int x, int y) const;
136 void write(std::ostream &) const;
138 void read(Lexer & lex);
140 int plaintext(odocstream &, OutputParams const &) const;
142 int docbook(odocstream &, OutputParams const &) const;
143 /// Update needed features for this inset.
144 void validate(LaTeXFeatures & features) const;
146 void addPreview(graphics::PreviewLoader &) const;
148 void edit(Cursor & cur, bool front, EntryDirection entry_from);
150 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
152 void doDispatch(Cursor & cur, FuncRequest & cmd);
154 Inset * clone() const { return new InsetExternal(*this); }
155 /** This method is connected to the graphics loader, so we are
156 * informed when the image has been loaded.
158 void statusChanged() const;
159 /** Slot receiving a signal that the external file has changed
160 * and the preview should be regenerated.
162 void fileChanged() const;
164 /// The current params
165 InsetExternalParams params_;
166 /// The thing that actually draws the image on LyX's screen.
167 boost::scoped_ptr<RenderBase> renderer_;
172 #endif // INSET_EXTERNAL_H