]> git.lyx.org Git - lyx.git/blob - src/insets/insetexternal.h
Re-add the RasterImage template.
[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 "graphics/GraphicsTypes.h"
17 #include "support/filename.h"
18
19 #include <boost/scoped_ptr.hpp>
20 #include <boost/signals/trackable.hpp>
21
22 #include "support/std_string.h"
23
24 class RenderInset;
25
26 ///
27 class InsetExternal : public InsetOld, public boost::signals::trackable
28 {
29         /** No two Params variables can have the same temporary file.
30          *  This struct has copy-semantics but the copy constructor
31          *  and assignment operator simply call the default constructor.
32          *  Use of this struct enables us to use the compiler-generated
33          *  copy constructor and assignment operator for the Params struct.
34          */
35         struct TempName {
36                 TempName();
37                 TempName(TempName const &);
38                 ~TempName();
39                 TempName & operator=(TempName const &);
40                 string const & operator()() const { return tempname_; }
41         private:
42                 string tempname_;
43         };
44
45 public:
46         /// hold parameters settable from the GUI
47         struct Params {
48                 Params();
49
50                 /// The name of the tempfile used for manipulations.
51                 string const & tempname() const { return tempname_(); }
52
53                 /// the current template used
54                 void settemplate(string const &);
55                 string const & templatename() const { return templatename_; }
56
57                 /// the filename
58                 lyx::support::FileName filename;
59                 /// how the inset is displayed by LyX
60                 lyx::graphics::DisplayType display;
61                 /// The scale of the displayed graphic (If shown).
62                 unsigned int lyxscale;
63
64         private:
65                 TempName tempname_;
66                 string templatename_;
67         };
68
69         InsetExternal();
70         ///
71         InsetExternal(InsetExternal const &);
72         ///
73         virtual ~InsetExternal();
74         ///
75         virtual dispatch_result localDispatch(FuncRequest const & cmd);
76         ///
77         void metrics(MetricsInfo &, Dimension &) const;
78         ///
79         void draw(PainterInfo & pi, int x, int y) const;
80         ///
81         virtual EDITABLE editable() const { return IS_EDITABLE; }
82         ///
83         virtual void write(Buffer const &, std::ostream &) const;
84         ///
85         virtual void read(Buffer const &, LyXLex & lex);
86
87         /** returns the number of rows (\n's) of generated tex code.
88          fragile == true means, that the inset should take care about
89          fragile commands by adding a \protect before.
90          If the free_spc (freespacing) variable is set, then this inset
91          is in a free-spacing paragraph.
92          */
93         virtual int latex(Buffer const &, std::ostream &,
94                           LatexRunParams const &) const;
95         /// write ASCII output to the ostream
96         virtual int ascii(Buffer const &, std::ostream &, int linelen) const;
97         /// write LinuxDoc output to the ostream
98         virtual int linuxdoc(Buffer const &, std::ostream &) const;
99         /// write DocBook output to the ostream
100         virtual int docbook(Buffer const &, std::ostream &, bool mixcont) const;
101
102         /// Updates needed features for this inset.
103         virtual void validate(LaTeXFeatures & features) const;
104
105         /// returns LyX code associated with the inset. Used for TOC, ...)
106         virtual InsetOld::Code lyxCode() const { return EXTERNAL_CODE; }
107
108         ///
109         virtual std::auto_ptr<InsetBase> clone() const;
110
111         /// return a copy of our current params
112         Params const & params() const;
113
114         /// Set the inset parameters.
115         virtual void setParams(Params const &, Buffer const &);
116
117         /** update the file represented by the template.
118             If \param external_in_tmpdir == true, then the generated file is
119             place in the buffer's temporary directory.
120         */
121         void updateExternal(string const &, Buffer const &,
122                             bool external_in_tmpdir) const;
123
124 private:
125         /** This method is connected to the graphics loader, so we are
126          *  informed when the image has been loaded.
127          */
128         void statusChanged();
129
130         /** Write the output for a specific file format
131             and generate any external data files.
132             If \param external_in_tmpdir == true, then the generated file is
133             place in the buffer's temporary directory.
134         */
135         int write(string const & format, Buffer const &, std::ostream &,
136                   bool external_in_tmpdir = false) const;
137
138         /// the current params
139         Params params_;
140
141         /// The thing that actually draws the image on LyX's screen.
142         boost::scoped_ptr<RenderInset> renderer_;
143 };
144
145
146 #include "mailinset.h"
147
148 class InsetExternalMailer : public MailInset {
149 public:
150         ///
151         InsetExternalMailer(InsetExternal & inset);
152         ///
153         virtual InsetBase & inset() const { return inset_; }
154         ///
155         virtual string const & name() const { return name_; }
156         ///
157         virtual string const inset2string(Buffer const &) const;
158         ///
159         static void string2params(string const &, Buffer const &,
160                                   InsetExternal::Params &);
161         ///
162         static string const params2string(InsetExternal::Params const &,
163                                           Buffer const &);
164 private:
165         ///
166         static string const name_;
167         ///
168         InsetExternal & inset_;
169 };
170
171 #endif