]> git.lyx.org Git - lyx.git/blob - src/insets/InsetExternal.h
Reduce caption hardcoding
[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
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/signals/trackable.hpp>
23
24
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.
31  */
32 namespace lyx {
33
34 namespace support {
35 class TempFile;
36 }
37
38 namespace external {
39
40 class TempName {
41 public:
42         TempName();
43         TempName(TempName const &);
44         ~TempName();
45         TempName & operator=(TempName const &);
46         support::FileName operator()() const;
47 private:
48         support::TempFile * tempfile_;
49 };
50
51 } // namespace external
52
53
54 /// hold parameters settable from the GUI
55 class InsetExternalParams {
56 public:
57         InsetExternalParams();
58
59         void write(Buffer const &, std::ostream &) const;
60         bool read(Buffer const &, Lexer &);
61
62         /// The name of the tempfile used for manipulations.
63         support::FileName tempname() const { return tempname_(); }
64
65         /// The template currently in use.
66         void settemplate(std::string const &);
67         std::string const & templatename() const { return templatename_; }
68
69         /// The external file.
70         support::DocFileName filename;
71         /// If the inset is to be displayed by LyX.
72         bool display;
73         /// If the inset is to use the preview mechanism.
74         PreviewMode preview_mode;
75         /// The scale of the displayed graphic (if shown).
76         unsigned int lyxscale;
77
78         external::ClipData     clipdata;
79         external::ExtraData    extradata;
80         external::ResizeData   resizedata;
81         external::RotationData rotationdata;
82
83         /** if \c true, simply output the filename, maybe wrapped in a
84          *  box, rather than generate and display the image etc.
85          */
86         bool draft;
87
88 private:
89         external::TempName tempname_;
90         std::string templatename_;
91 };
92
93
94 class RenderBase;
95
96 ///
97 class InsetExternal : public Inset, public boost::signals::trackable
98 {
99 public:
100         InsetExternal(Buffer *);
101         ///
102         ~InsetExternal();
103         ///
104         static void string2params(std::string const &, Buffer const &,
105                                   InsetExternalParams &);
106         ///
107         static std::string params2string(InsetExternalParams const &,
108                                                Buffer const &);
109         ///
110         InsetExternalParams const & params() const;
111         ///
112         void setParams(InsetExternalParams const &);
113         /// Update not loaded previews
114         void updatePreview();
115         /// \returns the number of rows (\n's) of generated code.
116         void latex(otexstream &, OutputParams const &) const;
117         ///
118         std::string contextMenuName() const;
119         ///
120         bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
121         ///
122         bool clickable(int, int) const { return true; }
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
167         /// The current params
168         InsetExternalParams params_;
169         /// The thing that actually draws the image on LyX's screen.
170         boost::scoped_ptr<RenderBase> renderer_;
171         /// changes color of the button when mouse enters/leaves this inset
172         mutable std::map<BufferView const *, bool> mouse_hover_;
173 };
174
175 } // namespace lyx
176
177 #endif // INSET_EXTERNAL_H