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
17 #include "ExternalTemplate.h"
19 #include "support/FileName.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 } // namespace external
50 /// hold parameters settable from the GUI
51 class InsetExternalParams {
53 InsetExternalParams();
55 void write(Buffer const &, std::ostream &) const;
56 bool read(Buffer const &, Lexer &);
58 /// The name of the tempfile used for manipulations.
59 support::FileName 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 support::DocFileName filename;
67 /// If the inset is to be displayed by LyX.
69 /// If the inset is to use the preview mechanism.
70 PreviewMode preview_mode;
71 /// The scale of the displayed graphic (if shown).
72 unsigned int lyxscale;
74 external::ClipData clipdata;
75 external::ExtraData extradata;
76 external::ResizeData resizedata;
77 external::RotationData rotationdata;
79 /** if \c true, simply output the filename, maybe wrapped in a
80 * box, rather than generate and display the image etc.
85 external::TempName tempname_;
86 std::string templatename_;
93 class InsetExternal : public Inset, public boost::signals::trackable
96 InsetExternal(Buffer *);
100 static void string2params(std::string const &, Buffer const &,
101 InsetExternalParams &);
103 static std::string params2string(InsetExternalParams const &,
106 InsetExternalParams const & params() const;
108 void setParams(InsetExternalParams const &);
109 /// Update not loaded previews
110 void updatePreview();
111 /// \returns the number of rows (\n's) of generated code.
112 void latex(otexstream &, OutputParams const &) const;
114 docstring contextMenuName() const;
116 bool setMouseHover(BufferView const * bv, bool mouse_hover);
118 bool clickable(int, int) const { return true; }
121 InsetExternal(InsetExternal const &);
123 InsetCode lyxCode() const { return EXTERNAL_CODE; }
125 bool hasSettings() const { return true; }
127 void metrics(MetricsInfo &, Dimension &) const;
129 void draw(PainterInfo & pi, int x, int y) const;
131 void write(std::ostream &) const;
133 void read(Lexer & lex);
135 int plaintext(odocstream &, OutputParams const &) const;
137 int docbook(odocstream &, OutputParams const &) const;
138 /// For now, this does nothing. Someone who knows about this
139 /// should see what needs doing for XHTML output.
140 docstring xhtml(XHTMLStream &, OutputParams const &) const;
141 /// Update needed features for this inset.
142 void validate(LaTeXFeatures & features) const;
144 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
146 bool showInsetDialog(BufferView * bv) const;
148 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
150 void doDispatch(Cursor & cur, FuncRequest & cmd);
152 Inset * clone() const { return new InsetExternal(*this); }
153 /** This method is connected to the graphics loader, so we are
154 * informed when the image has been loaded.
156 void statusChanged() const;
157 /** Slot receiving a signal that the external file has changed
158 * and the preview should be regenerated.
160 void fileChanged() const;
162 /// The current params
163 InsetExternalParams params_;
164 /// The thing that actually draws the image on LyX's screen.
165 boost::scoped_ptr<RenderBase> renderer_;
166 /// changes color of the button when mouse enters/leaves this inset
167 mutable std::map<BufferView const *, bool> mouse_hover_;
172 #endif // INSET_EXTERNAL_H