]> git.lyx.org Git - lyx.git/blob - src/insets/InsetExternal.h
5f9d9b7da712cc903979c44dde9bc4b91c2f2a30
[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 #include "ExternalTemplate.h"
17 #include "ExternalTransforms.h"
18
19 #include "support/FileName.h"
20 #include "support/Translator.h"
21
22 #include <boost/scoped_ptr.hpp>
23 #include <boost/signals/trackable.hpp>
24
25
26 /** No two InsetExternalParams variables can have the same temporary file.
27  *  This class has copy-semantics but the copy constructor
28  *  and assignment operator simply call the default constructor.
29  *  Use of this class enables us to use the compiler-generated
30  *  copy constructor and assignment operator for the
31  *  InsetExternalParams class.
32  */
33 namespace lyx {
34
35 namespace external {
36
37 class TempName {
38 public:
39         TempName();
40         TempName(TempName const &);
41         ~TempName();
42         TempName & operator=(TempName const &);
43         support::FileName const & operator()() const { return tempname_; }
44 private:
45         support::FileName tempname_;
46 };
47
48 } // namespace external
49
50
51 /// hold parameters settable from the GUI
52 class InsetExternalParams {
53 public:
54         InsetExternalParams();
55
56         void write(Buffer const &, std::ostream &) const;
57         bool read(Buffer const &, Lexer &);
58
59         /// The name of the tempfile used for manipulations.
60         support::FileName const & tempname() const { return tempname_(); }
61
62         /// The template currently in use.
63         void settemplate(std::string const &);
64         std::string const & templatename() const { return templatename_; }
65
66         /// The external file.
67         support::DocFileName filename;
68         /// If the inset is to be displayed by LyX.
69         bool display;
70         /// If the inset is to use the preview mechanism.
71         PreviewMode preview_mode;
72         /// The scale of the displayed graphic (if shown).
73         unsigned int lyxscale;
74
75         external::ClipData     clipdata;
76         external::ExtraData    extradata;
77         external::ResizeData   resizedata;
78         external::RotationData rotationdata;
79
80         /** if \c true, simply output the filename, maybe wrapped in a
81          *  box, rather than generate and display the image etc.
82          */
83         bool draft;
84
85 private:
86         external::TempName tempname_;
87         std::string templatename_;
88 };
89
90
91 class RenderBase;
92
93 ///
94 class InsetExternal : public Inset, public boost::signals::trackable
95 {
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();
112         /// \returns the number of rows (\n's) of generated code.
113         int latex(odocstream &, OutputParams const &) const;
114         ///
115         docstring contextMenu(BufferView const & bv, int x, int y) const;
116
117 private:
118         ///
119         InsetExternal(InsetExternal const &);
120         ///
121         InsetCode lyxCode() const { return EXTERNAL_CODE; }
122         ///
123         bool hasSettings() const { return true; }
124         ///
125         void metrics(MetricsInfo &, Dimension &) const;
126         ///
127         void draw(PainterInfo & pi, int x, int y) const;
128         ///
129         void write(std::ostream &) const;
130         ///
131         void read(Lexer & lex);
132         ///
133         int plaintext(odocstream &, OutputParams const &) const;
134         ///
135         int docbook(odocstream &, OutputParams const &) const;
136         /// For now, this does nothing. Someone who knows about this
137         /// should see what needs doing for XHTML output.
138         docstring xhtml(odocstream &, OutputParams const &) const;
139         /// Update needed features for this inset.
140         void validate(LaTeXFeatures & features) const;
141         ///
142         void addPreview(graphics::PreviewLoader &) const;
143         ///
144         bool showInsetDialog(BufferView * bv) const;
145         ///
146         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
147         ///
148         void doDispatch(Cursor & cur, FuncRequest & cmd);
149         ///
150         Inset * clone() const { return new InsetExternal(*this); }
151         /** This method is connected to the graphics loader, so we are
152          *  informed when the image has been loaded.
153          */
154         void statusChanged() const;
155         /** Slot receiving a signal that the external file has changed
156          *  and the preview should be regenerated.
157          */
158         void fileChanged() const;
159
160         /// The current params
161         InsetExternalParams params_;
162         /// The thing that actually draws the image on LyX's screen.
163         boost::scoped_ptr<RenderBase> renderer_;
164 };
165
166 } // namespace lyx
167
168 #endif // INSET_EXTERNAL_H