]> git.lyx.org Git - lyx.git/blob - src/insets/InsetExternal.h
Do not check again and again for non existing files
[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
23 namespace lyx {
24
25 namespace external {
26
27 /** No two InsetExternalParams variables can have the same temporary file.
28  *  This class has copy-semantics but the copy constructor
29  *  and assignment operator simply call the default constructor.
30  *  Use of this class enables us to use the compiler-generated
31  *  copy constructor and assignment operator for the
32  *  InsetExternalParams class.
33  */
34 class TempName {
35 public:
36         TempName();
37         TempName(TempName const &);
38         ~TempName();
39         TempName & operator=(TempName const &);
40         support::FileName operator()() const;
41 private:
42         support::FileName tempname_;
43 };
44
45 } // namespace external
46
47
48 /// hold parameters settable from the GUI
49 class InsetExternalParams {
50 public:
51         InsetExternalParams();
52
53         void write(Buffer const &, std::ostream &) const;
54         bool read(Buffer const &, Lexer &);
55
56         /// The name of the tempfile used for manipulations.
57         support::FileName tempname() const { return tempname_(); }
58
59         /// The template currently in use.
60         void settemplate(std::string const &);
61         std::string const & templatename() const { return templatename_; }
62
63         /// The external file.
64         support::DocFileName filename;
65         /// If the inset is to be displayed by LyX.
66         bool display;
67         /// If the inset is to use the preview mechanism.
68         PreviewMode preview_mode;
69         /// The scale of the displayed graphic (if shown).
70         unsigned int lyxscale;
71
72         external::ClipData     clipdata;
73         external::ExtraData    extradata;
74         external::ResizeData   resizedata;
75         external::RotationData rotationdata;
76
77         /** if \c true, simply output the filename, maybe wrapped in a
78          *  box, rather than generate and display the image etc.
79          */
80         bool draft;
81
82 private:
83         external::TempName tempname_;
84         std::string templatename_;
85 };
86
87
88 class RenderBase;
89
90 ///
91 class InsetExternal : public Inset
92 {
93         // Disable assignment operator, since it is not used, and it is too
94         // complicated to implement it consistently with the copy constructor
95         InsetExternal & operator=(InsetExternal const &);
96 public:
97         InsetExternal(Buffer *);
98         ///
99         ~InsetExternal();
100         ///
101         static void string2params(std::string const &, Buffer const &,
102                                   InsetExternalParams &);
103         ///
104         static std::string params2string(InsetExternalParams const &,
105                                                Buffer const &);
106         ///
107         InsetExternalParams const & params() const;
108         ///
109         void setParams(InsetExternalParams const &);
110         /// Update not loaded previews
111         void updatePreview() const;
112         /// \returns the number of rows (\n's) of generated code.
113         void latex(otexstream &, OutputParams const &) const;
114         ///
115         std::string contextMenuName() const;
116         ///
117         bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
118         ///
119         bool clickable(BufferView const &, int, int) const { return true; }
120         ///
121         void addToToc(DocIterator const & di, bool output_active,
122                                   UpdateType utype, TocBackend & backend) const;
123 private:
124         ///
125         InsetExternal(InsetExternal const &);
126         ///
127         InsetCode lyxCode() const { return EXTERNAL_CODE; }
128         ///
129         bool hasSettings() const { return true; }
130         ///
131         void metrics(MetricsInfo &, Dimension &) const;
132         ///
133         void draw(PainterInfo & pi, int x, int y) const;
134         ///
135         void write(std::ostream &) const;
136         ///
137         void read(Lexer & lex);
138         ///
139         int plaintext(odocstringstream & ods, OutputParams const & op,
140                       size_t max_length = INT_MAX) const;
141         ///
142         int docbook(odocstream &, OutputParams const &) const;
143         /// For now, this does nothing. Someone who knows about this
144         /// should see what needs doing for XHTML output.
145         docstring xhtml(XHTMLStream &, OutputParams const &) const;
146         /// Update needed features for this inset.
147         void validate(LaTeXFeatures & features) const;
148         ///
149         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
150         ///
151         bool showInsetDialog(BufferView * bv) const;
152         ///
153         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
154         ///
155         void doDispatch(Cursor & cur, FuncRequest & cmd);
156         ///
157         Inset * clone() const { return new InsetExternal(*this); }
158         /** This method is connected to the graphics loader, so we are
159          *  informed when the image has been loaded.
160          */
161         void statusChanged() const;
162         /** Slot receiving a signal that the external file has changed
163          *  and the preview should be regenerated.
164          */
165         void fileChanged() const;
166         /// Is this inset using (instant or graphics) preview?
167         bool isPreviewed() const;
168         /// Do we have the right renderer (button, graphic or monitored preview)?
169         bool isRendererValid() const;
170
171         /// The current params
172         InsetExternalParams params_;
173         /// The thing that actually draws the image on LyX's screen.
174         mutable unique_ptr<RenderBase> renderer_;
175         /// changes color of the button when mouse enters/leaves this inset
176         mutable std::map<BufferView const *, bool> mouse_hover_;
177 };
178
179 } // namespace lyx
180
181 #endif // INSET_EXTERNAL_H