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;
124 docstring contextMenu(BufferView const & bv, int x, int y) const;
128 InsetExternal(InsetExternal const &);
130 InsetCode lyxCode() const { return EXTERNAL_CODE; }
132 EDITABLE editable() const { return IS_EDITABLE; }
134 void metrics(MetricsInfo &, Dimension &) const;
136 void draw(PainterInfo & pi, int x, int y) const;
138 void write(std::ostream &) const;
140 void read(Lexer & lex);
142 int plaintext(odocstream &, OutputParams const &) const;
144 int docbook(odocstream &, OutputParams const &) const;
145 /// Update needed features for this inset.
146 void validate(LaTeXFeatures & features) const;
148 void addPreview(graphics::PreviewLoader &) const;
150 void edit(Cursor & cur, bool front, EntryDirection entry_from);
152 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
154 void doDispatch(Cursor & cur, FuncRequest & cmd);
156 Inset * clone() const { return new InsetExternal(*this); }
157 /** This method is connected to the graphics loader, so we are
158 * informed when the image has been loaded.
160 void statusChanged() const;
161 /** Slot receiving a signal that the external file has changed
162 * and the preview should be regenerated.
164 void fileChanged() const;
166 /// The current params
167 InsetExternalParams params_;
168 /// The thing that actually draws the image on LyX's screen.
169 boost::scoped_ptr<RenderBase> renderer_;
174 #endif // INSET_EXTERNAL_H