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