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>
29 /** No two InsetExternalParams variables can have the same temporary file.
30 * This class has copy-semantics but the copy constructor
31 * and assignment operator simply call the default constructor.
32 * Use of this class enables us to use the compiler-generated
33 * copy constructor and assignment operator for the
34 * InsetExternalParams class.
39 TempName(TempName const &);
41 TempName & operator=(TempName const &);
42 support::FileName operator()() const;
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 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
95 // Disable assignment operator, since it is not used, and it is too
96 // complicated to implement it consistently with the copy constructor
97 InsetExternal & operator=(InsetExternal const &);
99 InsetExternal(Buffer *);
103 static void string2params(std::string const &, Buffer const &,
104 InsetExternalParams &);
106 static std::string params2string(InsetExternalParams const &,
109 InsetExternalParams const & params() const;
111 void setParams(InsetExternalParams const &);
112 /// Update not loaded previews
113 void updatePreview();
114 /// \returns the number of rows (\n's) of generated code.
115 void latex(otexstream &, OutputParams const &) const;
117 std::string contextMenuName() const;
119 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
121 bool clickable(int, int) const { return true; }
123 void addToToc(DocIterator const & di, bool output_active,
124 UpdateType utype) const;
127 InsetExternal(InsetExternal const &);
129 InsetCode lyxCode() const { return EXTERNAL_CODE; }
131 bool hasSettings() const { return true; }
133 void metrics(MetricsInfo &, Dimension &) const;
135 void draw(PainterInfo & pi, int x, int y) const;
137 void write(std::ostream &) const;
139 void read(Lexer & lex);
141 int plaintext(odocstringstream & ods, OutputParams const & op,
142 size_t max_length = INT_MAX) const;
144 int docbook(odocstream &, OutputParams const &) const;
145 /// For now, this does nothing. Someone who knows about this
146 /// should see what needs doing for XHTML output.
147 docstring xhtml(XHTMLStream &, OutputParams const &) const;
148 /// Update needed features for this inset.
149 void validate(LaTeXFeatures & features) const;
151 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
153 bool showInsetDialog(BufferView * bv) const;
155 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
157 void doDispatch(Cursor & cur, FuncRequest & cmd);
159 Inset * clone() const { return new InsetExternal(*this); }
160 /** This method is connected to the graphics loader, so we are
161 * informed when the image has been loaded.
163 void statusChanged() const;
164 /** Slot receiving a signal that the external file has changed
165 * and the preview should be regenerated.
167 void fileChanged() const;
169 /// The current params
170 InsetExternalParams params_;
171 /// The thing that actually draws the image on LyX's screen.
172 boost::scoped_ptr<RenderBase> renderer_;
173 /// changes color of the button when mouse enters/leaves this inset
174 mutable std::map<BufferView const *, bool> mouse_hover_;
179 #endif // INSET_EXTERNAL_H