]> git.lyx.org Git - lyx.git/blob - src/insets/InsetExternal.h
Remove TextClassPtr without losing the type safety it provided.
[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 "ExternalTransforms.h"
17 #include "EmbeddedFiles.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 #include "MailInset.h"
26
27
28 /** No two InsetExternalParams variables can have the same temporary file.
29  *  This class has copy-semantics but the copy constructor
30  *  and assignment operator simply call the default constructor.
31  *  Use of this class enables us to use the compiler-generated
32  *  copy constructor and assignment operator for the
33  *  InsetExternalParams class.
34  */
35 namespace lyx {
36
37 namespace external {
38
39 class TempName {
40 public:
41         TempName();
42         TempName(TempName const &);
43         ~TempName();
44         TempName & operator=(TempName const &);
45         support::FileName const & operator()() const { return tempname_; }
46 private:
47         support::FileName tempname_;
48 };
49
50 /// How is the image to be displayed on the LyX screen?
51 enum DisplayType {
52         DefaultDisplay,
53         MonochromeDisplay,
54         GrayscaleDisplay,
55         ColorDisplay,
56         PreviewDisplay,
57         NoDisplay
58 };
59
60
61 /// The translator between the Display enum and corresponding lyx string.
62 Translator<DisplayType, std::string> const & displayTranslator();
63
64 } // namespace external
65
66
67 /// hold parameters settable from the GUI
68 class InsetExternalParams {
69 public:
70         InsetExternalParams();
71
72         void write(Buffer const &, std::ostream &) const;
73         bool read(Buffer const &, Lexer &);
74
75         /// The name of the tempfile used for manipulations.
76         support::FileName const & tempname() const { return tempname_(); }
77
78         /// The template currently in use.
79         void settemplate(std::string const &);
80         std::string const & templatename() const { return templatename_; }
81
82         /// The external file.
83         EmbeddedFile filename;
84         /// How the inset is to be displayed by LyX.
85         external::DisplayType display;
86         /// The scale of the displayed graphic (if shown).
87         unsigned int lyxscale;
88
89         external::ClipData     clipdata;
90         external::ExtraData    extradata;
91         external::ResizeData   resizedata;
92         external::RotationData rotationdata;
93
94         /** if \c true, simply output the filename, maybe wrapped in a
95          *  box, rather than generate and display the image etc.
96          */
97         bool draft;
98
99 private:
100         external::TempName tempname_;
101         std::string templatename_;
102 };
103
104
105 class RenderBase;
106
107 ///
108 class InsetExternal : public Inset, public boost::signals::trackable
109 {
110 public:
111         InsetExternal();
112         ///
113         ~InsetExternal();
114         ///
115         InsetCode lyxCode() const { return EXTERNAL_CODE; }
116         ///
117         EDITABLE editable() const { return IS_EDITABLE; }
118
119         ///
120         void metrics(MetricsInfo &, Dimension &) const;
121         ///
122         void draw(PainterInfo & pi, int x, int y) const;
123         ///
124         void write(std::ostream &) const;
125         ///
126         void read(Lexer & lex);
127
128         /// \returns the number of rows (\n's) of generated code.
129         int latex(odocstream &, OutputParams const &) const;
130         ///
131         int plaintext(odocstream &, OutputParams const &) const;
132         ///
133         int docbook(odocstream &, OutputParams const &) const;
134
135         /// Update needed features for this inset.
136         virtual void validate(LaTeXFeatures & features) const;
137
138         ///
139         InsetExternalParams const & params() const;
140         ///
141         void setParams(InsetExternalParams const &);
142         ///
143         void addPreview(graphics::PreviewLoader &) const;
144         ///
145         void edit(Cursor & cur, bool front, EntryDirection entry_from);
146         ///
147         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
148         /// external file can be embedded
149         void registerEmbeddedFiles(EmbeddedFileList &) const;
150         ///
151         void updateEmbeddedFile(EmbeddedFile const &);
152
153 protected:
154         InsetExternal(InsetExternal const &);
155         ///
156         void doDispatch(Cursor & cur, FuncRequest & cmd);
157 private:
158         Inset * clone() const;
159
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
165         /** Slot receiving a signal that the external file has changed
166          *  and the preview should be regenerated.
167          */
168         void fileChanged() const;
169
170         /// The current params
171         InsetExternalParams params_;
172         /// The thing that actually draws the image on LyX's screen.
173         boost::scoped_ptr<RenderBase> renderer_;
174 };
175
176
177 class InsetExternalMailer : public MailInset {
178 public:
179         ///
180         InsetExternalMailer(InsetExternal & inset);
181         ///
182         virtual Inset & inset() const { return inset_; }
183         ///
184         virtual std::string const & name() const { return name_; }
185         ///
186         virtual std::string const inset2string(Buffer const &) const;
187         ///
188         static void string2params(std::string const &, Buffer const &,
189                                   InsetExternalParams &);
190         ///
191         static std::string const params2string(InsetExternalParams const &,
192                                                Buffer const &);
193 private:
194         ///
195         static std::string const name_;
196         ///
197         InsetExternal & inset_;
198 };
199
200 } // namespace lyx
201
202 #endif