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 "graphics/GraphicsTypes.h"
20 #include "support/filename.h"
22 #include <boost/scoped_ptr.hpp>
23 #include <boost/signals/trackable.hpp>
24 #include <boost/weak_ptr.hpp>
27 /** No two InsetExternalParams variables can have the same temporary file.
28 * This struct has copy-semantics but the copy constructor
29 * and assignment operator simply call the default constructor.
30 * Use of this struct enables us to use the compiler-generated
31 * copy constructor and assignment operator for the
32 * InsetExternalParams struct.
39 TempName(TempName const &);
41 TempName & operator=(TempName const &);
42 std::string const & operator()() const { return tempname_; }
44 std::string tempname_;
47 } // namespace external
51 /// hold parameters settable from the GUI
52 struct InsetExternalParams {
53 InsetExternalParams();
55 void write(Buffer const &, std::ostream &) const;
56 bool read(Buffer const &, LyXLex &);
58 /// The name of the tempfile used for manipulations.
59 std::string const & tempname() const { return tempname_(); }
61 /// The template currently in use.
62 void settemplate(std::string const &);
63 std::string const & templatename() const { return templatename_; }
65 /// The external file.
66 lyx::support::FileName filename;
67 /// How the inset is to be displayed by LyX.
68 lyx::graphics::DisplayType display;
69 /// The scale of the displayed graphic (if shown).
70 unsigned int lyxscale;
72 lyx::external::ClipData clipdata;
73 lyx::external::ExtraData extradata;
74 lyx::external::ResizeData resizedata;
75 lyx::external::RotationData rotationdata;
78 lyx::external::TempName tempname_;
79 std::string templatename_;
86 class InsetExternal : public InsetOld, public boost::signals::trackable
91 InsetExternal(InsetExternal const &);
93 virtual ~InsetExternal();
95 virtual std::auto_ptr<InsetBase> clone() const;
97 virtual dispatch_result localDispatch(FuncRequest const & cmd);
100 virtual InsetOld::Code lyxCode() const { return EXTERNAL_CODE; }
102 virtual EDITABLE editable() const { return IS_EDITABLE; }
105 void metrics(MetricsInfo &, Dimension &) const;
107 void draw(PainterInfo & pi, int x, int y) const;
109 virtual void write(Buffer const &, std::ostream &) const;
111 virtual void read(Buffer const &, LyXLex & lex);
113 /// \returns the number of rows (\n's) of generated code.
114 virtual int latex(Buffer const &, std::ostream &,
115 LatexRunParams const &) const;
117 virtual int ascii(Buffer const &, std::ostream &, int linelen) const;
119 virtual int linuxdoc(Buffer const &, std::ostream &) const;
121 virtual int docbook(Buffer const &, std::ostream &,
124 /// Update needed features for this inset.
125 virtual void validate(LaTeXFeatures & features) const;
128 InsetExternalParams const & params() const;
129 void setParams(InsetExternalParams const &, Buffer const &);
132 void cache(BufferView *) const;
133 BufferView * view() const;
134 /** This method is connected to the graphics loader, so we are
135 * informed when the image has been loaded.
137 void statusChanged() const;
139 /// The current params
140 InsetExternalParams params_;
141 /// The thing that actually draws the image on LyX's screen.
142 boost::scoped_ptr<RenderBase> renderer_;
145 mutable boost::weak_ptr<BufferView> view_;
149 #include "mailinset.h"
151 class InsetExternalMailer : public MailInset {
154 InsetExternalMailer(InsetExternal & inset);
156 virtual InsetBase & inset() const { return inset_; }
158 virtual std::string const & name() const { return name_; }
160 virtual std::string const inset2string(Buffer const &) const;
162 static void string2params(std::string const &, Buffer const &,
163 InsetExternalParams &);
165 static std::string const params2string(InsetExternalParams const &,
169 static std::string const name_;
171 InsetExternal & inset_;