]> git.lyx.org Git - lyx.git/blob - src/insets/InsetExternal.h
Merge branch 'master' of git.lyx.org:lyx
[lyx.git] / src / insets / InsetExternal.h
1 // -*- C++ -*-
2 /**
3  * \file InsetExternal.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup Nielsen
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSET_EXTERNAL_H
13 #define INSET_EXTERNAL_H
14
15 #include "Inset.h"
16
17 #include "ExternalTemplate.h"
18
19 #include "support/FileName.h"
20 #include "support/unique_ptr.h"
21
22 #include <boost/signals2/trackable.hpp>
23
24
25 namespace lyx {
26
27 namespace external {
28
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.
35  */
36 class TempName {
37 public:
38         TempName();
39         TempName(TempName const &);
40         ~TempName();
41         TempName & operator=(TempName const &);
42         support::FileName operator()() const;
43 private:
44         support::FileName tempname_;
45 };
46
47 } // namespace external
48
49
50 /// hold parameters settable from the GUI
51 class InsetExternalParams {
52 public:
53         InsetExternalParams();
54
55         void write(Buffer const &, std::ostream &) const;
56         bool read(Buffer const &, Lexer &);
57
58         /// The name of the tempfile used for manipulations.
59         support::FileName tempname() const { return tempname_(); }
60
61         /// The template currently in use.
62         void settemplate(std::string const &);
63         std::string const & templatename() const { return templatename_; }
64
65         /// The external file.
66         support::DocFileName filename;
67         /// If the inset is to be displayed by LyX.
68         bool display;
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;
73
74         external::ClipData     clipdata;
75         external::ExtraData    extradata;
76         external::ResizeData   resizedata;
77         external::RotationData rotationdata;
78
79         /** if \c true, simply output the filename, maybe wrapped in a
80          *  box, rather than generate and display the image etc.
81          */
82         bool draft;
83
84 private:
85         external::TempName tempname_;
86         std::string templatename_;
87 };
88
89
90 class RenderBase;
91
92 ///
93 class InsetExternal : public Inset, public boost::signals2::trackable
94 {
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 &);
98 public:
99         InsetExternal(Buffer *);
100         ///
101         ~InsetExternal();
102         ///
103         static void string2params(std::string const &, Buffer const &,
104                                   InsetExternalParams &);
105         ///
106         static std::string params2string(InsetExternalParams const &,
107                                                Buffer const &);
108         ///
109         InsetExternalParams const & params() const;
110         ///
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;
116         ///
117         std::string contextMenuName() const;
118         ///
119         bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
120         ///
121         bool clickable(BufferView const &, int, int) const { return true; }
122         ///
123         void addToToc(DocIterator const & di, bool output_active,
124                                   UpdateType utype) const;
125 private:
126         ///
127         InsetExternal(InsetExternal const &);
128         ///
129         InsetCode lyxCode() const { return EXTERNAL_CODE; }
130         ///
131         bool hasSettings() const { return true; }
132         ///
133         void metrics(MetricsInfo &, Dimension &) const;
134         ///
135         void draw(PainterInfo & pi, int x, int y) const;
136         ///
137         void write(std::ostream &) const;
138         ///
139         void read(Lexer & lex);
140         ///
141         int plaintext(odocstringstream & ods, OutputParams const & op,
142                       size_t max_length = INT_MAX) const;
143         ///
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;
150         ///
151         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
152         ///
153         bool showInsetDialog(BufferView * bv) const;
154         ///
155         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
156         ///
157         void doDispatch(Cursor & cur, FuncRequest & cmd);
158         ///
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.
162          */
163         void statusChanged() const;
164         /** Slot receiving a signal that the external file has changed
165          *  and the preview should be regenerated.
166          */
167         void fileChanged() const;
168
169         /// The current params
170         InsetExternalParams params_;
171         /// The thing that actually draws the image on LyX's screen.
172         unique_ptr<RenderBase> renderer_;
173         /// changes color of the button when mouse enters/leaves this inset
174         mutable std::map<BufferView const *, bool> mouse_hover_;
175 };
176
177 } // namespace lyx
178
179 #endif // INSET_EXTERNAL_H